protobuf 2.8.0.beta6 → 2.8.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,6 +34,14 @@ module Protobuf
34
34
  def send_request
35
35
  raise 'If you inherit a Connector from Base you must implement send_request'
36
36
  end
37
+
38
+ def ping_port
39
+ @ping_port ||= ENV["PB_RPC_PING_PORT"]
40
+ end
41
+
42
+ def ping_port_enabled?
43
+ ENV.has_key?("PB_RPC_PING_PORT")
44
+ end
37
45
  end
38
46
  end
39
47
  end
@@ -43,7 +43,7 @@ module Protobuf
43
43
  #
44
44
  def send_request
45
45
  setup_connection
46
- send_request_with_lazy_pirate
46
+ send_request_with_lazy_pirate unless error?
47
47
  end
48
48
 
49
49
  def log_signature
@@ -87,16 +87,27 @@ module Protobuf
87
87
  # to the host and port in the options
88
88
  #
89
89
  def lookup_server_uri
90
- if service_directory.running?
90
+ begin
91
91
  listing = service_directory.lookup(service)
92
- host, port = listing.address, listing.port if listing
93
- end
94
-
95
- host, port = options[:host], options[:port] unless host && port
92
+ host = listing.try(:address) || options[:host]
93
+ port = listing.try(:port) || options[:port]
94
+ end until host_alive?( host )
96
95
 
97
96
  "tcp://#{host}:#{port}"
98
97
  end
99
98
 
99
+ def host_alive?(host)
100
+ return true unless ping_port_enabled?
101
+
102
+ socket = TCPSocket.new(host, ping_port.to_i)
103
+
104
+ true
105
+ rescue
106
+ false
107
+ ensure
108
+ socket.close rescue nil
109
+ end
110
+
100
111
  # Trying a number of times, attempt to get a response from the server.
101
112
  # If we haven't received a legitimate response in the CLIENT_RETRIES number
102
113
  # of retries, fail the request.
@@ -113,8 +124,6 @@ module Protobuf
113
124
  rescue RequestTimeout
114
125
  retry if attempt < CLIENT_RETRIES
115
126
  fail(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds")
116
- rescue => e
117
- fail(:RPC_FAILED, "Unexpected error sending request: #{e}")
118
127
  end
119
128
  end
120
129
 
@@ -19,8 +19,14 @@ module Protobuf
19
19
  def run
20
20
  @idle_workers = []
21
21
 
22
- while running?
23
- break if @poller.poll(500) < 0
22
+ loop do
23
+ rc = @poller.poll(500)
24
+
25
+ # The server was shutdown and no requests are pending
26
+ break if rc == 0 && !running?
27
+
28
+ # Something went wrong
29
+ break if rc == -1
24
30
 
25
31
  @poller.readables.each do |readable|
26
32
  case readable
@@ -41,10 +41,16 @@ module Protobuf
41
41
  # Send request to broker telling it we are ready
42
42
  write_to_backend([::Protobuf::Rpc::Zmq::WORKER_READY_MESSAGE])
43
43
 
44
- while running?
45
- break if poller.poll(500) < 0
44
+ loop do
45
+ rc = poller.poll(500)
46
46
 
47
- if poller.readables.any?
47
+ # The server was shutdown and no requests are pending
48
+ break if rc == 0 && !running?
49
+
50
+ # Something went wrong
51
+ break if rc == -1
52
+
53
+ if rc > 0
48
54
  initialize_request!
49
55
  process_request
50
56
  end
@@ -89,14 +89,16 @@ module Protobuf
89
89
  end
90
90
 
91
91
  def lookup(service)
92
- @mutex.synchronize do
93
- listings = @listings.values.select do |listing|
94
- listing.services.any? do |listed_service|
95
- listing.current? && listed_service == service.to_s
92
+ if running?
93
+ @mutex.synchronize do
94
+ listings = @listings.values.select do |listing|
95
+ listing.services.any? do |listed_service|
96
+ listing.current? && listed_service == service.to_s
97
+ end
96
98
  end
97
- end
98
99
 
99
- listings.sample
100
+ listings.sample
101
+ end
100
102
  end
101
103
  end
102
104
 
@@ -153,17 +155,6 @@ module Protobuf
153
155
  @socket = nil
154
156
  end
155
157
 
156
- def wait_for(service, timeout = DEFAULT_TIMEOUT)
157
- log_debug { sign_message("waiting for #{service}") }
158
- Timeout.timeout(timeout) do
159
- sleep(timeout / 10.0) until listing = lookup(service)
160
- listing
161
- end
162
- rescue
163
- log_info { sign_message("no listing found for #{service}") }
164
- nil
165
- end
166
-
167
158
  private
168
159
 
169
160
  def init_socket
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.8.0.beta6'
2
+ VERSION = '2.8.0.beta8'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -104,7 +104,7 @@ describe 'Functional ZMQ Client' do
104
104
  c.on_success { raise "shouldn't pass" }
105
105
  c.on_failure { |e| error = e }
106
106
  end
107
- error.message.should match(/The server took longer than 1 seconds to respond/i)
107
+ error.message.should match(/The server repeatedly failed to respond/)
108
108
  end
109
109
  end
110
110
 
@@ -52,13 +52,57 @@ describe ::Protobuf::Rpc::Connectors::Zmq do
52
52
  context "when the service directory is not running" do
53
53
  let(:running?) { false }
54
54
 
55
- it "does not search the directory" do
56
- service_directory.should_not_receive(:lookup)
55
+ it "defaults to the options" do
56
+ service_directory.should_receive(:lookup) { nil }
57
57
  subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400"
58
58
  end
59
59
  end
60
60
 
61
+ it "checks if the server is alive" do
62
+ service_directory.should_receive(:lookup) { nil }
63
+ subject.should_receive(:host_alive?).with("127.0.0.1") { true }
64
+ subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400"
65
+ end
66
+
61
67
  end
62
68
 
63
- pending
69
+ describe "#host_alive?" do
70
+ context "when the PB_RPC_PING_PORT is not set" do
71
+ before do
72
+ ENV.delete("PB_RPC_PING_PORT")
73
+ end
74
+
75
+ it "returns true" do
76
+ subject.send(:host_alive?, "yip.yip").should be_true
77
+ end
78
+
79
+ it "does not attempt a connection" do
80
+ TCPSocket.should_not_receive(:new)
81
+ subject.send(:host_alive?, "blargh.com")
82
+ end
83
+ end
84
+
85
+ context "when the PB_RPC_PING_PORT is set" do
86
+ before do
87
+ ENV["PB_RPC_PING_PORT"] = "3307"
88
+ end
89
+
90
+ it "returns true when the connection succeeds" do
91
+ TCPSocket.should_receive(:new).with("huzzah.com", 3307) { double(:close => nil) }
92
+ subject.send(:host_alive?, "huzzah.com").should be_true
93
+ end
94
+
95
+ it "returns false when the connection fails" do
96
+ TCPSocket.should_receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED)
97
+ subject.send(:host_alive?, "hayoob.com").should be_false
98
+ end
99
+
100
+ it "closes the socket" do
101
+ socket = double("TCPSocket")
102
+ socket.should_receive(:close)
103
+ TCPSocket.should_receive(:new).with("absorbalof.com", 3307) { socket }
104
+ subject.send(:host_alive?, "absorbalof.com").should be_true
105
+ end
106
+ end
107
+ end
64
108
  end
@@ -31,6 +31,10 @@ describe ::Protobuf::Rpc::ServiceDirectory do
31
31
  :ttl => 15) }
32
32
  let(:listing) { ::Protobuf::Rpc::ServiceDirectory::Listing.new(server) }
33
33
 
34
+ before do
35
+ instance.stub(:running?) { true }
36
+ end
37
+
34
38
  it "returns a listing for the given service" do
35
39
  instance.add_listing_for(server)
36
40
  instance.lookup("Known::Service").should eq listing
@@ -95,43 +99,6 @@ describe ::Protobuf::Rpc::ServiceDirectory do
95
99
  end
96
100
  end
97
101
 
98
- describe "#wait_for" do
99
- it "returns a listing for the given service" do
100
- server = double(:uuid => 1, :ttl => 5, :services => ["Test"])
101
- instance.add_listing_for server
102
- instance.lookup("Test").should eq server
103
- end
104
-
105
- it "depends on #lookup" do
106
- instance.stub(:lookup).with("Hayoob!") { "yup" }
107
- instance.wait_for("Hayoob!").should eq "yup"
108
- end
109
-
110
- it "waits for the service to appear" do
111
- server = double(:uuid => 1, :ttl => 5, :services => ["Test"])
112
-
113
- t = Thread.new do
114
- sleep 0.5
115
- instance.add_listing_for server
116
- end
117
-
118
- duration { instance.wait_for("Test") }.should be_within(0.01).of(0.5)
119
- t.join
120
- end
121
-
122
- it "returns nil if the service doesn't appear withint the timeout period" do
123
- server = double(:uuid => 1, :ttl => 5, :services => ["Test"])
124
-
125
- t = Thread.new do
126
- sleep 0.5
127
- instance.add_listing_for server
128
- end
129
-
130
- instance.wait_for("Test", 0.1).should be_nil
131
- t.join
132
- end
133
- end
134
-
135
102
  describe "a running service directory" do
136
103
  let(:socket) { UDPSocket.new }
137
104
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0.beta6
4
+ version: 2.8.0.beta8
5
+ prerelease: 6
5
6
  platform: ruby
6
7
  authors:
7
8
  - BJ Neilsen
@@ -9,188 +10,214 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-07-03 00:00:00.000000000 Z
13
+ date: 2013-07-15 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activesupport
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
- - - '>='
20
+ - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
22
  version: '0'
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
- - - '>='
28
+ - - ! '>='
26
29
  - !ruby/object:Gem::Version
27
30
  version: '0'
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: ffi
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
- - - '>='
36
+ - - ! '>='
33
37
  - !ruby/object:Gem::Version
34
38
  version: '0'
35
39
  type: :runtime
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
- - - '>='
44
+ - - ! '>='
40
45
  - !ruby/object:Gem::Version
41
46
  version: '0'
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: multi_json
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
- - - '>='
52
+ - - ! '>='
47
53
  - !ruby/object:Gem::Version
48
54
  version: '0'
49
55
  type: :runtime
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
- - - '>='
60
+ - - ! '>='
54
61
  - !ruby/object:Gem::Version
55
62
  version: '0'
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: thor
58
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
- - - '>='
68
+ - - ! '>='
61
69
  - !ruby/object:Gem::Version
62
70
  version: '0'
63
71
  type: :runtime
64
72
  prerelease: false
65
73
  version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
66
75
  requirements:
67
- - - '>='
76
+ - - ! '>='
68
77
  - !ruby/object:Gem::Version
69
78
  version: '0'
70
79
  - !ruby/object:Gem::Dependency
71
80
  name: eventmachine
72
81
  requirement: !ruby/object:Gem::Requirement
82
+ none: false
73
83
  requirements:
74
- - - '>='
84
+ - - ! '>='
75
85
  - !ruby/object:Gem::Version
76
86
  version: '0'
77
87
  type: :development
78
88
  prerelease: false
79
89
  version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
80
91
  requirements:
81
- - - '>='
92
+ - - ! '>='
82
93
  - !ruby/object:Gem::Version
83
94
  version: '0'
84
95
  - !ruby/object:Gem::Dependency
85
96
  name: ffi-rzmq
86
97
  requirement: !ruby/object:Gem::Requirement
98
+ none: false
87
99
  requirements:
88
- - - '>='
100
+ - - ! '>='
89
101
  - !ruby/object:Gem::Version
90
102
  version: '0'
91
103
  type: :development
92
104
  prerelease: false
93
105
  version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
94
107
  requirements:
95
- - - '>='
108
+ - - ! '>='
96
109
  - !ruby/object:Gem::Version
97
110
  version: '0'
98
111
  - !ruby/object:Gem::Dependency
99
112
  name: pry
100
113
  requirement: !ruby/object:Gem::Requirement
114
+ none: false
101
115
  requirements:
102
- - - '>='
116
+ - - ! '>='
103
117
  - !ruby/object:Gem::Version
104
118
  version: '0'
105
119
  type: :development
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
108
123
  requirements:
109
- - - '>='
124
+ - - ! '>='
110
125
  - !ruby/object:Gem::Version
111
126
  version: '0'
112
127
  - !ruby/object:Gem::Dependency
113
128
  name: pry-nav
114
129
  requirement: !ruby/object:Gem::Requirement
130
+ none: false
115
131
  requirements:
116
- - - '>='
132
+ - - ! '>='
117
133
  - !ruby/object:Gem::Version
118
134
  version: '0'
119
135
  type: :development
120
136
  prerelease: false
121
137
  version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
122
139
  requirements:
123
- - - '>='
140
+ - - ! '>='
124
141
  - !ruby/object:Gem::Version
125
142
  version: '0'
126
143
  - !ruby/object:Gem::Dependency
127
144
  name: rake
128
145
  requirement: !ruby/object:Gem::Requirement
146
+ none: false
129
147
  requirements:
130
- - - '>='
148
+ - - ! '>='
131
149
  - !ruby/object:Gem::Version
132
150
  version: '0'
133
151
  type: :development
134
152
  prerelease: false
135
153
  version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
136
155
  requirements:
137
- - - '>='
156
+ - - ! '>='
138
157
  - !ruby/object:Gem::Version
139
158
  version: '0'
140
159
  - !ruby/object:Gem::Dependency
141
160
  name: rake-compiler
142
161
  requirement: !ruby/object:Gem::Requirement
162
+ none: false
143
163
  requirements:
144
- - - '>='
164
+ - - ! '>='
145
165
  - !ruby/object:Gem::Version
146
166
  version: '0'
147
167
  type: :development
148
168
  prerelease: false
149
169
  version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
150
171
  requirements:
151
- - - '>='
172
+ - - ! '>='
152
173
  - !ruby/object:Gem::Version
153
174
  version: '0'
154
175
  - !ruby/object:Gem::Dependency
155
176
  name: rspec
156
177
  requirement: !ruby/object:Gem::Requirement
178
+ none: false
157
179
  requirements:
158
- - - '>='
180
+ - - ! '>='
159
181
  - !ruby/object:Gem::Version
160
182
  version: '0'
161
183
  type: :development
162
184
  prerelease: false
163
185
  version_requirements: !ruby/object:Gem::Requirement
186
+ none: false
164
187
  requirements:
165
- - - '>='
188
+ - - ! '>='
166
189
  - !ruby/object:Gem::Version
167
190
  version: '0'
168
191
  - !ruby/object:Gem::Dependency
169
192
  name: simplecov
170
193
  requirement: !ruby/object:Gem::Requirement
194
+ none: false
171
195
  requirements:
172
- - - '>='
196
+ - - ! '>='
173
197
  - !ruby/object:Gem::Version
174
198
  version: '0'
175
199
  type: :development
176
200
  prerelease: false
177
201
  version_requirements: !ruby/object:Gem::Requirement
202
+ none: false
178
203
  requirements:
179
- - - '>='
204
+ - - ! '>='
180
205
  - !ruby/object:Gem::Version
181
206
  version: '0'
182
207
  - !ruby/object:Gem::Dependency
183
208
  name: yard
184
209
  requirement: !ruby/object:Gem::Requirement
210
+ none: false
185
211
  requirements:
186
- - - '>='
212
+ - - ! '>='
187
213
  - !ruby/object:Gem::Version
188
214
  version: '0'
189
215
  type: :development
190
216
  prerelease: false
191
217
  version_requirements: !ruby/object:Gem::Requirement
218
+ none: false
192
219
  requirements:
193
- - - '>='
220
+ - - ! '>='
194
221
  - !ruby/object:Gem::Version
195
222
  version: '0'
196
223
  description: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for
@@ -468,111 +495,30 @@ files:
468
495
  - test/test_types.rb
469
496
  homepage: https://github.com/localshred/protobuf
470
497
  licenses: []
471
- metadata: {}
472
498
  post_install_message:
473
499
  rdoc_options: []
474
500
  require_paths:
475
501
  - lib
476
502
  required_ruby_version: !ruby/object:Gem::Requirement
503
+ none: false
477
504
  requirements:
478
- - - '>='
505
+ - - ! '>='
479
506
  - !ruby/object:Gem::Version
480
507
  version: '0'
508
+ segments:
509
+ - 0
510
+ hash: 1303972375277947888
481
511
  required_rubygems_version: !ruby/object:Gem::Requirement
512
+ none: false
482
513
  requirements:
483
- - - '>'
514
+ - - ! '>'
484
515
  - !ruby/object:Gem::Version
485
516
  version: 1.3.1
486
517
  requirements: []
487
518
  rubyforge_project:
488
- rubygems_version: 2.0.2
519
+ rubygems_version: 1.8.25
489
520
  signing_key:
490
- specification_version: 4
521
+ specification_version: 3
491
522
  summary: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for Ruby.
492
- test_files:
493
- - spec/benchmark/tasks.rb
494
- - spec/functional/embedded_service_spec.rb
495
- - spec/functional/evented_server_spec.rb
496
- - spec/functional/socket_server_spec.rb
497
- - spec/functional/zmq_server_spec.rb
498
- - spec/lib/protobuf/cli_spec.rb
499
- - spec/lib/protobuf/enum_spec.rb
500
- - spec/lib/protobuf/enum_value_spec.rb
501
- - spec/lib/protobuf/field/int32_field_spec.rb
502
- - spec/lib/protobuf/logger_spec.rb
503
- - spec/lib/protobuf/message_spec.rb
504
- - spec/lib/protobuf/rpc/client_spec.rb
505
- - spec/lib/protobuf/rpc/connector_spec.rb
506
- - spec/lib/protobuf/rpc/connectors/base_spec.rb
507
- - spec/lib/protobuf/rpc/connectors/common_spec.rb
508
- - spec/lib/protobuf/rpc/connectors/socket_spec.rb
509
- - spec/lib/protobuf/rpc/connectors/zmq_spec.rb
510
- - spec/lib/protobuf/rpc/servers/evented_server_spec.rb
511
- - spec/lib/protobuf/rpc/servers/socket_server_spec.rb
512
- - spec/lib/protobuf/rpc/servers/zmq/server_spec.rb
513
- - spec/lib/protobuf/rpc/servers/zmq/util_spec.rb
514
- - spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb
515
- - spec/lib/protobuf/rpc/service_directory_spec.rb
516
- - spec/lib/protobuf/rpc/service_dispatcher_spec.rb
517
- - spec/lib/protobuf/rpc/service_filters_spec.rb
518
- - spec/lib/protobuf/rpc/service_spec.rb
519
- - spec/lib/protobuf_spec.rb
520
- - spec/spec_helper.rb
521
- - spec/support/all.rb
522
- - spec/support/packed_field.rb
523
- - spec/support/server.rb
524
- - spec/support/test/enum.pb.rb
525
- - spec/support/test/enum.proto
526
- - spec/support/test/extended.pb.rb
527
- - spec/support/test/extended.proto
528
- - spec/support/test/multi_field_extensions.pb.rb
529
- - spec/support/test/multi_field_extensions.proto
530
- - spec/support/test/resource.pb.rb
531
- - spec/support/test/resource.proto
532
- - spec/support/test/resource_service.rb
533
- - spec/support/test_app_file.rb
534
- - spec/support/tolerance_matcher.rb
535
- - test/data/data.bin
536
- - test/data/data_source.py
537
- - test/data/types.bin
538
- - test/data/types_source.py
539
- - test/data/unk.png
540
- - test/proto/addressbook.pb.rb
541
- - test/proto/addressbook.proto
542
- - test/proto/addressbook_base.pb.rb
543
- - test/proto/addressbook_base.proto
544
- - test/proto/addressbook_ext.pb.rb
545
- - test/proto/addressbook_ext.proto
546
- - test/proto/collision.pb.rb
547
- - test/proto/collision.proto
548
- - test/proto/ext_collision.pb.rb
549
- - test/proto/ext_collision.proto
550
- - test/proto/ext_range.pb.rb
551
- - test/proto/ext_range.proto
552
- - test/proto/float_default.proto
553
- - test/proto/lowercase.pb.rb
554
- - test/proto/lowercase.proto
555
- - test/proto/merge.pb.rb
556
- - test/proto/merge.proto
557
- - test/proto/nested.pb.rb
558
- - test/proto/nested.proto
559
- - test/proto/optional_field.pb.rb
560
- - test/proto/optional_field.proto
561
- - test/proto/packed.pb.rb
562
- - test/proto/packed.proto
563
- - test/proto/rpc.proto
564
- - test/proto/types.pb.rb
565
- - test/proto/types.proto
566
- - test/test_addressbook.rb
567
- - test/test_enum_value.rb
568
- - test/test_extension.rb
569
- - test/test_lowercase.rb
570
- - test/test_message.rb
571
- - test/test_optional_field.rb
572
- - test/test_packed_field.rb
573
- - test/test_parse.rb
574
- - test/test_repeated_types.rb
575
- - test/test_serialize.rb
576
- - test/test_standard_message.rb
577
- - test/test_types.rb
523
+ test_files: []
578
524
  has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 8c1f25ffde20a579438083ec4b093a3b69e4df0e
4
- data.tar.gz: 5745bab0fb469561800260865054a5996a358e54
5
- SHA512:
6
- metadata.gz: d7f10fcee632cfd3dd496feaf6860d1fcc756b0196e08848033ed9fce721a03d37d01eed9e171debb60dbc829793600dc09b7f614d414995b77c1fa784f926d5
7
- data.tar.gz: d9099f622b4630c29273f287ca0eae438acc053533797b365fcbb1c5f303659439385fb3fff4a4887c6c4759036897da6e49780faf7ef3f26fcb55882a0f768c