protobuf 2.8.0.beta6-java → 2.8.0.beta8-java

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
@@ -2,7 +2,7 @@
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 2.8.0.beta6
5
+ version: 2.8.0.beta8
6
6
  platform: java
7
7
  authors:
8
8
  - BJ Neilsen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-03 00:00:00.000000000 Z
13
+ date: 2013-07-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -546,90 +546,5 @@ rubygems_version: 1.8.24
546
546
  signing_key:
547
547
  specification_version: 3
548
548
  summary: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for Ruby.
549
- test_files:
550
- - spec/benchmark/tasks.rb
551
- - spec/functional/embedded_service_spec.rb
552
- - spec/functional/evented_server_spec.rb
553
- - spec/functional/socket_server_spec.rb
554
- - spec/functional/zmq_server_spec.rb
555
- - spec/lib/protobuf/cli_spec.rb
556
- - spec/lib/protobuf/enum_spec.rb
557
- - spec/lib/protobuf/enum_value_spec.rb
558
- - spec/lib/protobuf/field/int32_field_spec.rb
559
- - spec/lib/protobuf/logger_spec.rb
560
- - spec/lib/protobuf/message_spec.rb
561
- - spec/lib/protobuf/rpc/client_spec.rb
562
- - spec/lib/protobuf/rpc/connector_spec.rb
563
- - spec/lib/protobuf/rpc/connectors/base_spec.rb
564
- - spec/lib/protobuf/rpc/connectors/common_spec.rb
565
- - spec/lib/protobuf/rpc/connectors/socket_spec.rb
566
- - spec/lib/protobuf/rpc/connectors/zmq_spec.rb
567
- - spec/lib/protobuf/rpc/servers/evented_server_spec.rb
568
- - spec/lib/protobuf/rpc/servers/socket_server_spec.rb
569
- - spec/lib/protobuf/rpc/servers/zmq/server_spec.rb
570
- - spec/lib/protobuf/rpc/servers/zmq/util_spec.rb
571
- - spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb
572
- - spec/lib/protobuf/rpc/service_directory_spec.rb
573
- - spec/lib/protobuf/rpc/service_dispatcher_spec.rb
574
- - spec/lib/protobuf/rpc/service_filters_spec.rb
575
- - spec/lib/protobuf/rpc/service_spec.rb
576
- - spec/lib/protobuf_spec.rb
577
- - spec/spec_helper.rb
578
- - spec/support/all.rb
579
- - spec/support/packed_field.rb
580
- - spec/support/server.rb
581
- - spec/support/test/enum.pb.rb
582
- - spec/support/test/enum.proto
583
- - spec/support/test/extended.pb.rb
584
- - spec/support/test/extended.proto
585
- - spec/support/test/multi_field_extensions.pb.rb
586
- - spec/support/test/multi_field_extensions.proto
587
- - spec/support/test/resource.pb.rb
588
- - spec/support/test/resource.proto
589
- - spec/support/test/resource_service.rb
590
- - spec/support/test_app_file.rb
591
- - spec/support/tolerance_matcher.rb
592
- - test/data/data.bin
593
- - test/data/data_source.py
594
- - test/data/types.bin
595
- - test/data/types_source.py
596
- - test/data/unk.png
597
- - test/proto/addressbook.pb.rb
598
- - test/proto/addressbook.proto
599
- - test/proto/addressbook_base.pb.rb
600
- - test/proto/addressbook_base.proto
601
- - test/proto/addressbook_ext.pb.rb
602
- - test/proto/addressbook_ext.proto
603
- - test/proto/collision.pb.rb
604
- - test/proto/collision.proto
605
- - test/proto/ext_collision.pb.rb
606
- - test/proto/ext_collision.proto
607
- - test/proto/ext_range.pb.rb
608
- - test/proto/ext_range.proto
609
- - test/proto/float_default.proto
610
- - test/proto/lowercase.pb.rb
611
- - test/proto/lowercase.proto
612
- - test/proto/merge.pb.rb
613
- - test/proto/merge.proto
614
- - test/proto/nested.pb.rb
615
- - test/proto/nested.proto
616
- - test/proto/optional_field.pb.rb
617
- - test/proto/optional_field.proto
618
- - test/proto/packed.pb.rb
619
- - test/proto/packed.proto
620
- - test/proto/rpc.proto
621
- - test/proto/types.pb.rb
622
- - test/proto/types.proto
623
- - test/test_addressbook.rb
624
- - test/test_enum_value.rb
625
- - test/test_extension.rb
626
- - test/test_lowercase.rb
627
- - test/test_message.rb
628
- - test/test_optional_field.rb
629
- - test/test_packed_field.rb
630
- - test/test_parse.rb
631
- - test/test_repeated_types.rb
632
- - test/test_serialize.rb
633
- - test/test_standard_message.rb
634
- - test/test_types.rb
549
+ test_files: []
635
550
  has_rdoc: