protobuf 2.8.6 → 2.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGES.md +6 -0
- data/README.md +1 -2
- data/lib/protobuf/rpc/client.rb +4 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +15 -7
- data/lib/protobuf/rpc/service.rb +4 -0
- data/lib/protobuf/rpc/service_directory.rb +8 -0
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +13 -4
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa760a7ec58543a5e0cc40c95f95240646291506
|
4
|
+
data.tar.gz: ecd9644df44958b8f3330b574c119ba3b15e9f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d33d3de6834639e094746377c53f3cebd3116306ec235fb358ce7be64ed18e2d158fdb79eb216e294ce8417a1d2962622a66d5e430245620bbd07290190d84eb
|
7
|
+
data.tar.gz: f3e322395f7c27c30559869d8df4147a80da23a391f4020c5df19db58295fd5a3414c18bc7198cef0100af50ce15128c2f9df83a1ee109795878334307bae9f6
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -3,8 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf)
|
4
4
|
[![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf)
|
5
5
|
|
6
|
-
___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) for
|
7
|
-
API changes.___
|
6
|
+
___See [CHANGES.md](https://github.com/localshred/protobuf/blob/master/CHANGES.md) or [Release Notes](https://github.com/localshred/protobuf/releases) for significant version changes.___
|
8
7
|
|
9
8
|
Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported.
|
10
9
|
|
data/lib/protobuf/rpc/client.rb
CHANGED
@@ -87,13 +87,21 @@ module Protobuf
|
|
87
87
|
# to the host and port in the options
|
88
88
|
#
|
89
89
|
def lookup_server_uri
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
5.times do
|
91
|
+
service_directory.all_listings_for(service).each do |listing|
|
92
|
+
host = listing.try(:address)
|
93
|
+
port = listing.try(:port)
|
94
|
+
return "tcp://#{host}:#{port}" if host_alive?(host)
|
95
|
+
end
|
96
|
+
|
97
|
+
host = options[:host]
|
98
|
+
port = options[:port]
|
99
|
+
return "tcp://#{host}:#{port}" if host_alive?(host)
|
100
|
+
|
101
|
+
sleep 1
|
102
|
+
end
|
95
103
|
|
96
|
-
"
|
104
|
+
raise "Host not found for service #{service}"
|
97
105
|
end
|
98
106
|
|
99
107
|
def host_alive?(host)
|
@@ -145,7 +153,7 @@ module Protobuf
|
|
145
153
|
end
|
146
154
|
ensure
|
147
155
|
log_debug { sign_message("Closing Socket") }
|
148
|
-
zmq_error_check(socket.close, :socket_close)
|
156
|
+
zmq_error_check(socket.close, :socket_close) if socket
|
149
157
|
log_debug { sign_message("Socket closed") }
|
150
158
|
end
|
151
159
|
|
data/lib/protobuf/rpc/service.rb
CHANGED
@@ -85,6 +85,14 @@ module Protobuf
|
|
85
85
|
reset
|
86
86
|
end
|
87
87
|
|
88
|
+
def all_listings_for(service)
|
89
|
+
if running? && @listings_by_service.key?(service.to_s)
|
90
|
+
@listings_by_service[service.to_s].entries.shuffle
|
91
|
+
else
|
92
|
+
[]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
88
96
|
def each_listing(&block)
|
89
97
|
@listings_by_uuid.each_value(&block)
|
90
98
|
end
|
data/lib/protobuf/version.rb
CHANGED
@@ -31,6 +31,7 @@ describe ::Protobuf::Rpc::Connectors::Zmq do
|
|
31
31
|
describe "#lookup_server_uri" do
|
32
32
|
let(:service_directory) { double('ServiceDirectory', :running? => running? ) }
|
33
33
|
let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) }
|
34
|
+
let(:listings) { [listing] }
|
34
35
|
let(:running?) { true }
|
35
36
|
|
36
37
|
before do
|
@@ -39,12 +40,12 @@ describe ::Protobuf::Rpc::Connectors::Zmq do
|
|
39
40
|
|
40
41
|
context "when the service directory is running" do
|
41
42
|
it "searches the service directory" do
|
42
|
-
service_directory.
|
43
|
+
service_directory.stub(:all_listings_for).and_return(listings)
|
43
44
|
subject.send(:lookup_server_uri).should eq "tcp://127.0.0.2:9399"
|
44
45
|
end
|
45
46
|
|
46
47
|
it "defaults to the options" do
|
47
|
-
service_directory.
|
48
|
+
service_directory.stub(:all_listings_for).and_return([])
|
48
49
|
subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400"
|
49
50
|
end
|
50
51
|
end
|
@@ -53,17 +54,25 @@ describe ::Protobuf::Rpc::Connectors::Zmq do
|
|
53
54
|
let(:running?) { false }
|
54
55
|
|
55
56
|
it "defaults to the options" do
|
56
|
-
service_directory.
|
57
|
+
service_directory.stub(:all_listings_for).and_return([])
|
57
58
|
subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400"
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
62
|
it "checks if the server is alive" do
|
62
|
-
service_directory.
|
63
|
+
service_directory.stub(:all_listings_for).and_return([])
|
63
64
|
subject.should_receive(:host_alive?).with("127.0.0.1") { true }
|
64
65
|
subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400"
|
65
66
|
end
|
66
67
|
|
68
|
+
context "when no host is alive" do
|
69
|
+
it "raises an error" do
|
70
|
+
service_directory.stub(:all_listings_for).and_return(listings)
|
71
|
+
subject.stub(:host_alive?).and_return(false)
|
72
|
+
expect { subject.send(:lookup_server_uri) }.to raise_error
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
67
76
|
end
|
68
77
|
|
69
78
|
describe "#host_alive?" do
|
@@ -154,6 +154,23 @@ describe ::Protobuf::Rpc::ServiceDirectory do
|
|
154
154
|
send_beacon(:flatline, echo_server)
|
155
155
|
end
|
156
156
|
|
157
|
+
describe "#all_listings_for" do
|
158
|
+
context "when listings are present" do
|
159
|
+
it "returns all listings for a given service" do
|
160
|
+
send_beacon(:heartbeat, hello_server)
|
161
|
+
send_beacon(:heartbeat, combo_server)
|
162
|
+
|
163
|
+
subject.all_listings_for("HelloService").size.should eq(2)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when no listings are present" do
|
168
|
+
it "returns and empty array" do
|
169
|
+
subject.all_listings_for("HelloService").size.should eq(0)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
157
174
|
describe "#each_listing" do
|
158
175
|
it "should yield to a block for each listing" do
|
159
176
|
send_beacon(:heartbeat, hello_server)
|
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.8.
|
4
|
+
version: 2.8.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BJ Neilsen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|