protobuf 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,6 +14,8 @@ So let's dive in and see how to work with all three.
14
14
 
15
15
  ## 1. Generating ruby classes from `.proto` files
16
16
 
17
+ _The `protobuf` package is required for compilation. Mac: `brew install protobuf`, Ubuntu: `sudo apt-get install -y protobuf`_
18
+
17
19
  Protocol Buffers are great because they allow you to clearly define data storage or data transfer packets. Google officially supports Java, C++, and Python for compilation and usage. Let's make it ruby aware!
18
20
 
19
21
  Let's say you have a `defs.proto` file that defines a User message.
@@ -24,9 +26,11 @@ message User {
24
26
  required string first_name = 1;
25
27
  required string last_name = 2;
26
28
  }
29
+ ```
27
30
 
28
31
  Now let's compile that definition to ruby:
29
32
 
33
+ ```
30
34
  $ rprotoc defs.proto --ruby_out ./lib
31
35
  ```
32
36
 
data/lib/protobuf.rb CHANGED
@@ -14,6 +14,19 @@ module Protobuf
14
14
 
15
15
  module_function
16
16
 
17
+ # Client Host
18
+ #
19
+ # Default: `hostname` of the system
20
+ #
21
+ # The name or address of the host to use during client RPC calls.
22
+ def self.client_host
23
+ @_client_host ||= `hostname`.chomp
24
+ end
25
+
26
+ def self.client_host=(host)
27
+ @_client_host = host
28
+ end
29
+
17
30
  # Connector Type
18
31
  #
19
32
  # Default: socket
@@ -9,14 +9,15 @@ module Protobuf
9
9
  module Rpc
10
10
  module Connectors
11
11
  DEFAULT_OPTIONS = {
12
- :service => nil, # Service to invoke
13
- :method => nil, # Service method to call
14
- :host => '127.0.0.1', # A default host (usually overridden)
15
- :port => '9399', # A default port (usually overridden)
12
+ :service => nil, # Fully-qualified Service class
13
+ :method => nil, # Service method to invoke
14
+ :host => '127.0.0.1', # The hostname or address of the service (usually overridden or pre-configured)
15
+ :port => '9399', # The port of the service (usually overridden or pre-configured)
16
16
  :request => nil, # The request object sent by the client
17
17
  :request_type => nil, # The request type expected by the client
18
18
  :response_type => nil, # The response type expected by the client
19
- :timeout => 30 # The default timeout for the request, also handled by client.rb
19
+ :timeout => 30, # The default timeout for the request, also handled by client.rb
20
+ :client_host => nil # The hostname or address of this client
20
21
  }
21
22
 
22
23
  class Base
@@ -11,6 +11,10 @@ module Protobuf
11
11
  end
12
12
  end
13
13
 
14
+ def request_caller
15
+ @options[:client_host] || ::Protobuf.client_host
16
+ end
17
+
14
18
  def complete
15
19
  @stats.stop
16
20
  log_info { @stats.to_s }
@@ -101,21 +105,21 @@ module Protobuf
101
105
  fail(:RPC_ERROR, "Connection error: #{e.message}")
102
106
  end
103
107
 
104
- def rpc_request_data
105
- validate_request_type
108
+ def request_bytes
109
+ validate_request_type!
110
+ fields = { :service_name => @options[:service].name,
111
+ :method_name => @options[:method].to_s,
112
+ :request_proto => @options[:request],
113
+ :caller => request_caller }
106
114
 
107
- return ::Protobuf::Socketrpc::Request.new(
108
- :service_name => @options[:service].name,
109
- :method_name => @options[:method].to_s,
110
- :request_proto => @options[:request]
111
- ).serialize_to_string
115
+ return ::Protobuf::Socketrpc::Request.new(fields).serialize_to_string
112
116
  rescue => e
113
117
  fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}")
114
118
  end
115
119
 
116
120
  def setup_connection
117
121
  initialize_stats
118
- @request_data = rpc_request_data
122
+ @request_data = request_bytes
119
123
  end
120
124
 
121
125
  def succeed(response)
@@ -129,7 +133,7 @@ module Protobuf
129
133
  complete
130
134
  end
131
135
 
132
- def validate_request_type
136
+ def validate_request_type!
133
137
  unless @options[:request].class == @options[:request_type]
134
138
  expected = @options[:request_type].name
135
139
  actual = @options[:request].class.name
@@ -138,13 +142,13 @@ module Protobuf
138
142
  end
139
143
 
140
144
  def verify_callbacks
141
- if !any_callbacks?
145
+ unless any_callbacks?
142
146
  log_debug { sign_message("No callbacks set, using data_callback") }
143
147
  @success_cb = @failure_cb = self.method(:data_callback)
144
148
  end
145
149
  end
146
150
 
147
- def verify_options
151
+ def verify_options!
148
152
  # Verify the options that are necessary and merge them in
149
153
  [:service, :method, :host, :port].each do |opt|
150
154
  fail(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil?
@@ -17,7 +17,7 @@ module Protobuf
17
17
  @failure_cb = failure_cb
18
18
  @options = DEFAULT_OPTIONS.merge(options)
19
19
  @response_buffer = ::Protobuf::Rpc::Buffer.new(:read)
20
- verify_options
20
+ verify_options!
21
21
 
22
22
  log_debug { sign_message("Client Initialized: #{options.inspect}") }
23
23
  rescue => e
@@ -1,78 +1,6 @@
1
- ### Generated by rprotoc. DO NOT EDIT!
2
- ### <proto file: rpc.proto>
3
- # // Copyright (c) 2009 Shardul Deo
4
- # //
5
- # // Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # // of this software and associated documentation files (the "Software"), to deal
7
- # // in the Software without restriction, including without limitation the rights
8
- # // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # // copies of the Software, and to permit persons to whom the Software is
10
- # // furnished to do so, subject to the following conditions:
11
- # //
12
- # // The above copyright notice and this permission notice shall be included in
13
- # // all copies or substantial portions of the Software.
14
- # //
15
- # // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # // THE SOFTWARE.
22
- #
23
- # // Author: Shardul Deo
24
- # //
25
- # // Protobufs needed for socket rpcs.
26
- #
27
- # package protobuf.socketrpc;
28
- #
29
- # message Request {
30
- #
31
- # // RPC service full name
32
- # required string service_name = 1;
33
- #
34
- # // RPC method name
35
- # required string method_name = 2;
36
- #
37
- # // RPC request proto
38
- # required bytes request_proto = 3;
39
- # }
40
- #
41
- # message Response {
42
- #
43
- # // RPC response proto
44
- # optional bytes response_proto = 1;
45
- #
46
- # // Error, if any
47
- # optional string error = 2;
48
- #
49
- # // Was callback invoked
50
- # optional bool callback = 3 [default = false];
51
- #
52
- # // Error Reason
53
- # optional ErrorReason error_reason = 4;
54
- # }
55
- #
56
- # // Possible error reasons
57
- # // The server-side errors are returned in the response from the server.
58
- # // The client-side errors are returned by the client-side code when it doesn't
59
- # // have a response from the server.
60
- # enum ErrorReason {
61
- #
62
- # // Server-side errors
63
- # BAD_REQUEST_DATA = 0; // Server received bad request data
64
- # BAD_REQUEST_PROTO = 1; // Server received bad request proto
65
- # SERVICE_NOT_FOUND = 2; // Service not found on server
66
- # METHOD_NOT_FOUND = 3; // Method not found on server
67
- # RPC_ERROR = 4; // Rpc threw exception on server
68
- # RPC_FAILED = 5; // Rpc failed on server
69
- #
70
- # // Client-side errors (these are returned by the client-side code)
71
- # INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto
72
- # BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto
73
- # UNKNOWN_HOST = 8; // Could not find supplied host
74
- # IO_ERROR = 9; // I/O error while communicating with server
75
- # }
1
+ ##
2
+ # This file is auto-generated. DO NOT EDIT!
3
+ #
76
4
  require 'protobuf/message'
77
5
 
78
6
  module Protobuf
@@ -91,28 +19,35 @@ module Protobuf
91
19
  ##
92
20
  # Enum Values
93
21
  #
94
- ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0
95
- ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1
96
- ::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2
97
- ::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3
98
- ::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4
99
- ::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5
100
- ::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6
101
- ::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7
102
- ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8
103
- ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9
22
+ class ErrorReason
23
+ define :BAD_REQUEST_DATA, 0
24
+ define :BAD_REQUEST_PROTO, 1
25
+ define :SERVICE_NOT_FOUND, 2
26
+ define :METHOD_NOT_FOUND, 3
27
+ define :RPC_ERROR, 4
28
+ define :RPC_FAILED, 5
29
+ define :INVALID_REQUEST_PROTO, 6
30
+ define :BAD_RESPONSE_PROTO, 7
31
+ define :UNKNOWN_HOST, 8
32
+ define :IO_ERROR, 9
33
+ end
104
34
 
105
35
  ##
106
36
  # Message Fields
107
37
  #
108
- ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1)
109
- ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2)
110
- ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::BytesField, :request_proto, 3)
38
+ class Request
39
+ required ::Protobuf::Field::StringField, :service_name, 1
40
+ required ::Protobuf::Field::StringField, :method_name, 2
41
+ optional ::Protobuf::Field::BytesField, :request_proto, 3
42
+ optional ::Protobuf::Field::StringField, :caller, 4
43
+ end
111
44
 
112
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1)
113
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2)
114
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false)
115
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4)
45
+ class Response
46
+ optional ::Protobuf::Field::BytesField, :response_proto, 1
47
+ optional ::Protobuf::Field::StringField, :error, 2
48
+ optional ::Protobuf::Field::BoolField, :callback, 3, :default => false
49
+ optional ::Protobuf::Socketrpc::ErrorReason, :error_reason, 4
50
+ end
116
51
 
117
52
  end
118
53
  end
@@ -14,7 +14,6 @@ module Protobuf
14
14
  @request = ::Protobuf::Socketrpc::Request.new
15
15
  @response = ::Protobuf::Socketrpc::Response.new
16
16
  @stats = Protobuf::Rpc::Stat.new(:SERVER)
17
- set_peer
18
17
  end
19
18
 
20
19
  def disable_gc!
@@ -25,12 +24,11 @@ module Protobuf
25
24
  ::GC.enable && ::GC.start if ::Protobuf.gc_pause_server_request?
26
25
  end
27
26
 
28
- # no-op, implemented by including class if desired.
29
- def set_peer; end
30
-
31
27
  # Invoke the service method dictated by the proto wrapper request object
32
28
  def handle_client
33
29
  parse_request_from_buffer
30
+ @stats.client = @request.caller
31
+
34
32
  @dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(@request)
35
33
  @stats.dispatcher = @dispatcher
36
34
 
@@ -31,10 +31,6 @@ module Protobuf
31
31
  log_debug { sign_message("sending data: #{response_buffer.inspect}") }
32
32
  super(response_buffer.write)
33
33
  end
34
-
35
- def set_peer
36
- @stats.client = ::Socket.unpack_sockaddr_in(get_peername)
37
- end
38
34
  end
39
35
  end
40
36
  end
@@ -74,7 +74,7 @@ module Protobuf
74
74
  client, sockaddr = @server.accept
75
75
  @listen_fds << client
76
76
  else
77
- if !@working.include?(client)
77
+ unless @working.include?(client)
78
78
  @working << @listen_fds.delete(client)
79
79
  log_debug { sign_message("Working") }
80
80
  @threads << { :thread => new_worker(client), :socket => client }
@@ -52,10 +52,6 @@ module Protobuf
52
52
  @_log_signature ||= "server-#{self.class}-#{object_id}"
53
53
  end
54
54
 
55
- def set_peer
56
- @stats.client = ::Socket.unpack_sockaddr_in(@socket.getpeername)
57
- end
58
-
59
55
  def socket_writable?
60
56
  ! @socket.nil? && ! @socket.closed?
61
57
  end
@@ -29,7 +29,7 @@ module Protobuf
29
29
  def handle_request(socket)
30
30
  @request_data = ''
31
31
  zmq_error_check(socket.recv_string(@request_data))
32
- log_debug { sign_message("handling request") } if !@request_data.nil?
32
+ log_debug { sign_message("handling request") } unless @request_data.nil?
33
33
  end
34
34
 
35
35
  def run
@@ -15,8 +15,6 @@ module Protobuf
15
15
  include ::Protobuf::Logger::LogMethods
16
16
 
17
17
 
18
- attr_reader :response, :rpc
19
-
20
18
  DEFAULT_HOST = '127.0.0.1'.freeze
21
19
  DEFAULT_PORT = 9399
22
20
 
@@ -102,23 +100,26 @@ module Protobuf
102
100
  # Instance Methods
103
101
  #
104
102
 
103
+ attr_reader :response, :method_name, :client_host
104
+
105
105
  # Initialize a service with the rpc endpoint name and the bytes
106
106
  # for the request.
107
- def initialize(rpc, request_bytes)
108
- @rpc = rpc
109
- @request_bytes = request_bytes
107
+ def initialize(method_name, request_bytes, client_host = nil)
108
+ @method_name = method_name
109
+ @client_host = client_host
110
+ @_request_bytes = request_bytes
110
111
  end
111
112
 
112
113
  # Register a failure callback for use when rpc_failed is invoked.
113
114
  #
114
115
  def on_rpc_failed(callable)
115
- @rpc_failed_callback ||= callable
116
+ @_rpc_failed_callback ||= callable
116
117
  end
117
118
 
118
119
  # Response object for this rpc cycle. Not assignable.
119
120
  #
120
121
  def response
121
- @_response ||= rpcs[@rpc].response_type.new
122
+ @_response ||= response_type.new
122
123
  end
123
124
 
124
125
  # Convenience method to get back to class method.
@@ -144,18 +145,26 @@ module Protobuf
144
145
 
145
146
  private
146
147
 
148
+ def response_type
149
+ @_response_type ||= rpcs[@method_name].response_type
150
+ end
151
+
147
152
  # Request object for this rpc cycle. Not assignable.
148
153
  #
149
154
  def request
150
- @_request ||= if @request_bytes.present?
151
- rpcs[@rpc].request_type.new.parse_from_string(@request_bytes)
155
+ @_request ||= if @_request_bytes.present?
156
+ request_type.new.parse_from_string(@_request_bytes)
152
157
  else
153
- rpcs[@rpc].request_type.new
158
+ request_type.new
154
159
  end
155
160
  rescue => e
156
161
  raise BadRequestProto, "Unable to parse request: #{e.message}"
157
162
  end
158
163
 
164
+ def request_type
165
+ @_request_type ||= rpcs[@method_name].request_type
166
+ end
167
+
159
168
  # Sugar to make an rpc method feel like a controller method.
160
169
  # If this method is not called, the response will be the memoized
161
170
  # object returned by the response reader.
@@ -165,10 +174,22 @@ module Protobuf
165
174
  end
166
175
  alias_method :return_from_whence_you_came, :respond_with
167
176
 
177
+ # Renamed attribute from prior implementaiton due to lack of clarity
178
+ # in what the variable contained. DEPRECATED.
179
+ def rpc
180
+ if ::Protobuf.print_deprecation_warnings?
181
+ $stderr.puts <<-ERROR
182
+ [WARNING] Service#rpc method has been deprecated
183
+ and will be removed in a future version of protobuf.
184
+ ERROR
185
+ end
186
+ @method_name
187
+ end
188
+
168
189
  # Automatically fail a service method.
169
190
  #
170
191
  def rpc_failed(message)
171
- @rpc_failed_callback.call(message)
192
+ @_rpc_failed_callback.call(message)
172
193
  end
173
194
 
174
195
  end
@@ -74,7 +74,7 @@ module Protobuf
74
74
  request_proto = outer_request.has_field?(:request_proto) ? outer_request.request_proto : nil
75
75
 
76
76
  if service_klass.rpc_method?(method_name)
77
- self.service = service_klass.new(method_name, request_proto)
77
+ self.service = service_klass.new(method_name, request_proto, outer_request.caller)
78
78
  self.callable_method = service.callable_rpc_method(method_name)
79
79
  self.definition = service.rpcs[method_name]
80
80
  else
@@ -14,12 +14,12 @@ module Protobuf
14
14
  start
15
15
  end
16
16
 
17
- def client=(peer)
18
- @client = {:port => peer[0], :ip => peer[1]}
17
+ def client=(client_host)
18
+ @client = client_host
19
19
  end
20
20
 
21
21
  def client
22
- @client ? "#{@client[:ip]}:#{@client[:port]}" : nil
22
+ @client || nil
23
23
  end
24
24
 
25
25
  def method_name
@@ -47,7 +47,7 @@ module Protobuf
47
47
  end
48
48
 
49
49
  def stop
50
- start if !@start_time
50
+ start unless @start_time
51
51
  @end_time ||= Time.now
52
52
  end
53
53
 
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.5.0'
2
+ VERSION = '2.5.1'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
data/proto/rpc.proto CHANGED
@@ -18,56 +18,45 @@
18
18
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  // THE SOFTWARE.
20
20
 
21
- // Author: Shardul Deo
21
+ // Authors: Shardul Deo, BJ Neilsen
22
22
  //
23
23
  // Protobufs needed for socket rpcs.
24
24
 
25
25
  package protobuf.socketrpc;
26
26
 
27
- message Request {
28
-
29
- // RPC service full name
30
- required string service_name = 1;
31
-
32
- // RPC method name
33
- required string method_name = 2;
34
-
35
- // RPC request proto
36
- optional bytes request_proto = 3;
27
+ message Request
28
+ {
29
+ required string service_name = 1; // Fully- qualified Service class name
30
+ required string method_name = 2; // Service method to invoke
31
+ optional bytes request_proto = 3; // Serialized request bytes
32
+ optional string caller = 4; // Calling hostname or address
37
33
  }
38
34
 
39
- message Response {
40
-
41
- // RPC response proto
42
- optional bytes response_proto = 1;
43
-
44
- // Error, if any
45
- optional string error = 2;
46
-
47
- // Was callback invoked
48
- optional bool callback = 3 [default = false];
49
-
50
- // Error Reason
51
- optional ErrorReason error_reason = 4;
35
+ message Response
36
+ {
37
+ optional bytes response_proto = 1; // Serialized response
38
+ optional string error = 2; // Error message, if any
39
+ optional bool callback = 3 [default = false]; // Was callback invoked (not sure what this is for)
40
+ optional ErrorReason error_reason = 4; // Error Reason
52
41
  }
53
42
 
54
43
  // Possible error reasons
55
44
  // The server-side errors are returned in the response from the server.
56
- // The client-side errors are returned by the client-side code when it doesn't
45
+ // The client-side errors are returned by the client-side code when it doesn't
57
46
  // have a response from the server.
58
- enum ErrorReason {
59
-
47
+ enum ErrorReason
48
+ {
60
49
  // Server-side errors
61
- BAD_REQUEST_DATA = 0; // Server received bad request data
62
- BAD_REQUEST_PROTO = 1; // Server received bad request proto
63
- SERVICE_NOT_FOUND = 2; // Service not found on server
64
- METHOD_NOT_FOUND = 3; // Method not found on server
65
- RPC_ERROR = 4; // Rpc threw exception on server
66
- RPC_FAILED = 5; // Rpc failed on server
67
-
50
+ BAD_REQUEST_DATA = 0; // Server received bad request data
51
+ BAD_REQUEST_PROTO = 1; // Server received bad request proto
52
+ SERVICE_NOT_FOUND = 2; // Service not found on server
53
+ METHOD_NOT_FOUND = 3; // Method not found on server
54
+ RPC_ERROR = 4; // Rpc threw exception on server
55
+ RPC_FAILED = 5; // Rpc failed on server
56
+
68
57
  // Client-side errors (these are returned by the client-side code)
69
- INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto
70
- BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto
71
- UNKNOWN_HOST = 8; // Could not find supplied host
72
- IO_ERROR = 9; // I/O error while communicating with server
58
+ INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto
59
+ BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto
60
+ UNKNOWN_HOST = 8; // Could not find supplied host
61
+ IO_ERROR = 9; // I/O error while communicating with server
73
62
  }
@@ -10,20 +10,23 @@ describe Protobuf::Rpc::Connectors::Common do
10
10
  end
11
11
  end
12
12
 
13
- subject{ @subject ||= common_class.new({}) }
13
+ let(:subject_options) { {} }
14
+
15
+ subject { @subject ||= common_class.new(subject_options) }
14
16
 
15
17
  context "API" do
16
- specify{ subject.respond_to?(:any_callbacks?).should be_true }
17
- specify{ subject.respond_to?(:data_callback).should be_true }
18
- specify{ subject.respond_to?(:error).should be_true }
19
- specify{ subject.respond_to?(:fail).should be_true }
20
- specify{ subject.respond_to?(:complete).should be_true }
21
- specify{ subject.respond_to?(:parse_response).should be_true }
22
- specify{ subject.respond_to?(:verify_options).should be_true }
23
- specify{ subject.respond_to?(:verify_callbacks).should be_true }
18
+ specify { subject.respond_to?(:any_callbacks?).should be_true }
19
+ specify { subject.respond_to?(:request_caller).should be_true }
20
+ specify { subject.respond_to?(:data_callback).should be_true }
21
+ specify { subject.respond_to?(:error).should be_true }
22
+ specify { subject.respond_to?(:fail).should be_true }
23
+ specify { subject.respond_to?(:complete).should be_true }
24
+ specify { subject.respond_to?(:parse_response).should be_true }
25
+ specify { subject.respond_to?(:verify_options!).should be_true }
26
+ specify { subject.respond_to?(:verify_callbacks).should be_true }
24
27
  end
25
28
 
26
- context "#any_callbacks?" do
29
+ describe "#any_callbacks?" do
27
30
 
28
31
  [:@complete_cb, :@success_cb, :@failure_cb].each do |cb|
29
32
  it "returns true if #{cb} is provided" do
@@ -42,7 +45,19 @@ describe Protobuf::Rpc::Connectors::Common do
42
45
 
43
46
  end
44
47
 
45
- context "#data_callback" do
48
+ describe '#request_caller' do
49
+ its(:request_caller) { should eq ::Protobuf.client_host }
50
+
51
+ context 'when "client_host" option is given to initializer' do
52
+ let(:hostname) { 'myhost.myserver.com' }
53
+ let(:subject_options) { { :client_host => hostname } }
54
+
55
+ its(:request_caller) { should_not eq ::Protobuf.client_host }
56
+ its(:request_caller) { should eq hostname }
57
+ end
58
+ end
59
+
60
+ describe "#data_callback" do
46
61
  it "changes state to use the data callback" do
47
62
  subject.data_callback("data")
48
63
  subject.instance_variable_get(:@used_data_callback).should be_true
@@ -54,7 +69,28 @@ describe Protobuf::Rpc::Connectors::Common do
54
69
  end
55
70
  end
56
71
 
57
- context "#verify_callbacks" do
72
+ describe '#request_bytes' do
73
+ let(:service) { Test::ResourceService }
74
+ let(:method) { :find }
75
+ let(:request) { '' }
76
+ let(:client_host) { 'myhost.myservice.com' }
77
+ let(:subject_options) { { :service => service,
78
+ :method => method,
79
+ :request => request,
80
+ :client_host => client_host } }
81
+
82
+ let(:expected) { ::Protobuf::Socketrpc::Request.new({ :service_name => service.name,
83
+ :method_name => 'find',
84
+ :request_proto => '',
85
+ :caller => client_host }) }
86
+
87
+ before { subject.stub(:validate_request_type!).and_return(true) }
88
+ before { subject.should_not_receive(:fail) }
89
+
90
+ its(:request_bytes) { should eq expected.serialize_to_string }
91
+ end
92
+
93
+ describe "#verify_callbacks" do
58
94
 
59
95
  it "sets @failure_cb to #data_callback when no callbacks are defined" do
60
96
  subject.verify_callbacks
@@ -3,6 +3,22 @@ require 'protobuf'
3
3
 
4
4
  describe ::Protobuf do
5
5
 
6
+ describe '.client_host' do
7
+ after { ::Protobuf.instance_variable_set(:@_client_host, nil) }
8
+
9
+ subject { ::Protobuf.client_host }
10
+
11
+ context 'when client_host is not pre-configured' do
12
+ it { should eq `hostname`.chomp }
13
+ end
14
+
15
+ context 'when client_host is pre-configured' do
16
+ let(:hostname) { 'override.myhost.com' }
17
+ before { ::Protobuf.client_host = hostname }
18
+ it { should eq hostname }
19
+ end
20
+ end
21
+
6
22
  describe '.connector_type' do
7
23
  before { described_class.instance_variable_set(:@_connector_type, nil) }
8
24
 
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: 2.5.0
4
+ version: 2.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-28 00:00:00.000000000 Z
13
+ date: 2012-11-29 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &2152959680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,15 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
25
+ version_requirements: *2152959680
31
26
  - !ruby/object:Gem::Dependency
32
27
  name: ffi
33
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &2152958340 !ruby/object:Gem::Requirement
34
29
  none: false
35
30
  requirements:
36
31
  - - ! '>='
@@ -38,15 +33,10 @@ dependencies:
38
33
  version: '0'
39
34
  type: :runtime
40
35
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
36
+ version_requirements: *2152958340
47
37
  - !ruby/object:Gem::Dependency
48
38
  name: multi_json
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &2152956800 !ruby/object:Gem::Requirement
50
40
  none: false
51
41
  requirements:
52
42
  - - ! '>='
@@ -54,15 +44,10 @@ dependencies:
54
44
  version: '0'
55
45
  type: :runtime
56
46
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
47
+ version_requirements: *2152956800
63
48
  - !ruby/object:Gem::Dependency
64
49
  name: thor
65
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &2152954460 !ruby/object:Gem::Requirement
66
51
  none: false
67
52
  requirements:
68
53
  - - ! '>='
@@ -70,15 +55,10 @@ dependencies:
70
55
  version: '0'
71
56
  type: :runtime
72
57
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
58
+ version_requirements: *2152954460
79
59
  - !ruby/object:Gem::Dependency
80
60
  name: eventmachine
81
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &2152953240 !ruby/object:Gem::Requirement
82
62
  none: false
83
63
  requirements:
84
64
  - - ! '>='
@@ -86,15 +66,10 @@ dependencies:
86
66
  version: '0'
87
67
  type: :development
88
68
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
69
+ version_requirements: *2152953240
95
70
  - !ruby/object:Gem::Dependency
96
71
  name: ffi-rzmq
97
- requirement: !ruby/object:Gem::Requirement
72
+ requirement: &2152951540 !ruby/object:Gem::Requirement
98
73
  none: false
99
74
  requirements:
100
75
  - - ! '>='
@@ -102,15 +77,10 @@ dependencies:
102
77
  version: '0'
103
78
  type: :development
104
79
  prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
80
+ version_requirements: *2152951540
111
81
  - !ruby/object:Gem::Dependency
112
82
  name: pry
113
- requirement: !ruby/object:Gem::Requirement
83
+ requirement: &2152950140 !ruby/object:Gem::Requirement
114
84
  none: false
115
85
  requirements:
116
86
  - - ! '>='
@@ -118,15 +88,10 @@ dependencies:
118
88
  version: '0'
119
89
  type: :development
120
90
  prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0'
91
+ version_requirements: *2152950140
127
92
  - !ruby/object:Gem::Dependency
128
93
  name: pry-nav
129
- requirement: !ruby/object:Gem::Requirement
94
+ requirement: &2152948840 !ruby/object:Gem::Requirement
130
95
  none: false
131
96
  requirements:
132
97
  - - ! '>='
@@ -134,15 +99,10 @@ dependencies:
134
99
  version: '0'
135
100
  type: :development
136
101
  prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: '0'
102
+ version_requirements: *2152948840
143
103
  - !ruby/object:Gem::Dependency
144
104
  name: rake
145
- requirement: !ruby/object:Gem::Requirement
105
+ requirement: &2152947240 !ruby/object:Gem::Requirement
146
106
  none: false
147
107
  requirements:
148
108
  - - ! '>='
@@ -150,15 +110,10 @@ dependencies:
150
110
  version: '0'
151
111
  type: :development
152
112
  prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
- requirements:
156
- - - ! '>='
157
- - !ruby/object:Gem::Version
158
- version: '0'
113
+ version_requirements: *2152947240
159
114
  - !ruby/object:Gem::Dependency
160
115
  name: rake-compiler
161
- requirement: !ruby/object:Gem::Requirement
116
+ requirement: &2152946020 !ruby/object:Gem::Requirement
162
117
  none: false
163
118
  requirements:
164
119
  - - ! '>='
@@ -166,15 +121,10 @@ dependencies:
166
121
  version: '0'
167
122
  type: :development
168
123
  prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
172
- - - ! '>='
173
- - !ruby/object:Gem::Version
174
- version: '0'
124
+ version_requirements: *2152946020
175
125
  - !ruby/object:Gem::Dependency
176
126
  name: rspec
177
- requirement: !ruby/object:Gem::Requirement
127
+ requirement: &2152871420 !ruby/object:Gem::Requirement
178
128
  none: false
179
129
  requirements:
180
130
  - - ! '>='
@@ -182,15 +132,10 @@ dependencies:
182
132
  version: '0'
183
133
  type: :development
184
134
  prerelease: false
185
- version_requirements: !ruby/object:Gem::Requirement
186
- none: false
187
- requirements:
188
- - - ! '>='
189
- - !ruby/object:Gem::Version
190
- version: '0'
135
+ version_requirements: *2152871420
191
136
  - !ruby/object:Gem::Dependency
192
137
  name: simplecov
193
- requirement: !ruby/object:Gem::Requirement
138
+ requirement: &2152865540 !ruby/object:Gem::Requirement
194
139
  none: false
195
140
  requirements:
196
141
  - - ! '>='
@@ -198,15 +143,10 @@ dependencies:
198
143
  version: '0'
199
144
  type: :development
200
145
  prerelease: false
201
- version_requirements: !ruby/object:Gem::Requirement
202
- none: false
203
- requirements:
204
- - - ! '>='
205
- - !ruby/object:Gem::Version
206
- version: '0'
146
+ version_requirements: *2152865540
207
147
  - !ruby/object:Gem::Dependency
208
148
  name: yard
209
- requirement: !ruby/object:Gem::Requirement
149
+ requirement: &2152816060 !ruby/object:Gem::Requirement
210
150
  none: false
211
151
  requirements:
212
152
  - - ! '>='
@@ -214,12 +154,7 @@ dependencies:
214
154
  version: '0'
215
155
  type: :development
216
156
  prerelease: false
217
- version_requirements: !ruby/object:Gem::Requirement
218
- none: false
219
- requirements:
220
- - - ! '>='
221
- - !ruby/object:Gem::Version
222
- version: '0'
157
+ version_requirements: *2152816060
223
158
  description: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for
224
159
  Ruby.
225
160
  email:
@@ -402,7 +337,6 @@ files:
402
337
  - lib/protobuf/version.rb
403
338
  - lib/protobuf/wire_type.rb
404
339
  - lib/protobuf/zmq.rb
405
- - proto/rpc.pb.rb
406
340
  - proto/rpc.proto
407
341
  - protobuf.gemspec
408
342
  - spec/benchmark/tasks.rb
@@ -498,7 +432,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
498
432
  version: '0'
499
433
  segments:
500
434
  - 0
501
- hash: 2566852558843863563
435
+ hash: -4197432233485309916
502
436
  required_rubygems_version: !ruby/object:Gem::Requirement
503
437
  none: false
504
438
  requirements:
@@ -507,12 +441,91 @@ required_rubygems_version: !ruby/object:Gem::Requirement
507
441
  version: '0'
508
442
  segments:
509
443
  - 0
510
- hash: 2566852558843863563
444
+ hash: -4197432233485309916
511
445
  requirements: []
512
446
  rubyforge_project:
513
- rubygems_version: 1.8.24
447
+ rubygems_version: 1.8.15
514
448
  signing_key:
515
449
  specification_version: 3
516
450
  summary: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for Ruby.
517
- test_files: []
451
+ test_files:
452
+ - spec/benchmark/tasks.rb
453
+ - spec/functional/embedded_service_spec.rb
454
+ - spec/functional/evented_server_spec.rb
455
+ - spec/functional/socket_server_spec.rb
456
+ - spec/functional/zmq_server_spec.rb
457
+ - spec/lib/protobuf/cli_spec.rb
458
+ - spec/lib/protobuf/enum_spec.rb
459
+ - spec/lib/protobuf/enum_value_spec.rb
460
+ - spec/lib/protobuf/logger_spec.rb
461
+ - spec/lib/protobuf/message_spec.rb
462
+ - spec/lib/protobuf/rpc/client_spec.rb
463
+ - spec/lib/protobuf/rpc/connector_spec.rb
464
+ - spec/lib/protobuf/rpc/connectors/base_spec.rb
465
+ - spec/lib/protobuf/rpc/connectors/common_spec.rb
466
+ - spec/lib/protobuf/rpc/connectors/socket_spec.rb
467
+ - spec/lib/protobuf/rpc/connectors/zmq_spec.rb
468
+ - spec/lib/protobuf/rpc/servers/evented_server_spec.rb
469
+ - spec/lib/protobuf/rpc/servers/socket_server_spec.rb
470
+ - spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb
471
+ - spec/lib/protobuf/rpc/servers/zmq/server_spec.rb
472
+ - spec/lib/protobuf/rpc/servers/zmq/util_spec.rb
473
+ - spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb
474
+ - spec/lib/protobuf/rpc/service_dispatcher_spec.rb
475
+ - spec/lib/protobuf/rpc/service_filters_spec.rb
476
+ - spec/lib/protobuf/rpc/service_spec.rb
477
+ - spec/lib/protobuf_spec.rb
478
+ - spec/spec_helper.rb
479
+ - spec/support/all.rb
480
+ - spec/support/server.rb
481
+ - spec/support/test/enum.pb.rb
482
+ - spec/support/test/enum.proto
483
+ - spec/support/test/resource.pb.rb
484
+ - spec/support/test/resource.proto
485
+ - spec/support/test/resource_service.rb
486
+ - spec/support/test_app_file.rb
487
+ - spec/support/tolerance_matcher.rb
488
+ - test/data/data.bin
489
+ - test/data/data_source.py
490
+ - test/data/types.bin
491
+ - test/data/types_source.py
492
+ - test/data/unk.png
493
+ - test/proto/addressbook.pb.rb
494
+ - test/proto/addressbook.proto
495
+ - test/proto/addressbook_base.pb.rb
496
+ - test/proto/addressbook_base.proto
497
+ - test/proto/addressbook_ext.pb.rb
498
+ - test/proto/addressbook_ext.proto
499
+ - test/proto/collision.pb.rb
500
+ - test/proto/collision.proto
501
+ - test/proto/ext_collision.pb.rb
502
+ - test/proto/ext_collision.proto
503
+ - test/proto/ext_range.pb.rb
504
+ - test/proto/ext_range.proto
505
+ - test/proto/float_default.proto
506
+ - test/proto/lowercase.pb.rb
507
+ - test/proto/lowercase.proto
508
+ - test/proto/merge.pb.rb
509
+ - test/proto/merge.proto
510
+ - test/proto/nested.pb.rb
511
+ - test/proto/nested.proto
512
+ - test/proto/optional_field.pb.rb
513
+ - test/proto/optional_field.proto
514
+ - test/proto/packed.pb.rb
515
+ - test/proto/packed.proto
516
+ - test/proto/rpc.proto
517
+ - test/proto/types.pb.rb
518
+ - test/proto/types.proto
519
+ - test/test_addressbook.rb
520
+ - test/test_enum_value.rb
521
+ - test/test_extension.rb
522
+ - test/test_lowercase.rb
523
+ - test/test_message.rb
524
+ - test/test_optional_field.rb
525
+ - test/test_packed_field.rb
526
+ - test/test_parse.rb
527
+ - test/test_repeated_types.rb
528
+ - test/test_serialize.rb
529
+ - test/test_standard_message.rb
530
+ - test/test_types.rb
518
531
  has_rdoc:
data/proto/rpc.pb.rb DELETED
@@ -1,48 +0,0 @@
1
- ##
2
- # This file is auto-generated. DO NOT EDIT!
3
- #
4
- require 'protobuf/message'
5
-
6
- module Protobuf
7
- module Socketrpc
8
- ##
9
- # Enum Classes
10
- #
11
- class ErrorReason < ::Protobuf::Enum; end
12
-
13
- ##
14
- # Message Classes
15
- #
16
- class Request < ::Protobuf::Message; end
17
- class Response < ::Protobuf::Message; end
18
-
19
- ##
20
- # Enum Values
21
- #
22
- ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_DATA, 0
23
- ::Protobuf::Socketrpc::ErrorReason.define :BAD_REQUEST_PROTO, 1
24
- ::Protobuf::Socketrpc::ErrorReason.define :SERVICE_NOT_FOUND, 2
25
- ::Protobuf::Socketrpc::ErrorReason.define :METHOD_NOT_FOUND, 3
26
- ::Protobuf::Socketrpc::ErrorReason.define :RPC_ERROR, 4
27
- ::Protobuf::Socketrpc::ErrorReason.define :RPC_FAILED, 5
28
- ::Protobuf::Socketrpc::ErrorReason.define :INVALID_REQUEST_PROTO, 6
29
- ::Protobuf::Socketrpc::ErrorReason.define :BAD_RESPONSE_PROTO, 7
30
- ::Protobuf::Socketrpc::ErrorReason.define :UNKNOWN_HOST, 8
31
- ::Protobuf::Socketrpc::ErrorReason.define :IO_ERROR, 9
32
-
33
-
34
- ##
35
- # Message Fields
36
- #
37
- ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :service_name, 1)
38
- ::Protobuf::Socketrpc::Request.required(::Protobuf::Field::StringField, :method_name, 2)
39
- ::Protobuf::Socketrpc::Request.optional(::Protobuf::Field::BytesField, :request_proto, 3)
40
-
41
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BytesField, :response_proto, 1)
42
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::StringField, :error, 2)
43
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Field::BoolField, :callback, 3, :default => false)
44
- ::Protobuf::Socketrpc::Response.optional(::Protobuf::Socketrpc::ErrorReason, :error_reason, 4)
45
-
46
-
47
- end
48
- end