protobuf 2.7.11-java → 2.8.0.beta1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +39 -2
- data/lib/protobuf.rb +17 -26
- data/lib/protobuf/cli.rb +106 -86
- data/lib/protobuf/field/float_field.rb +5 -1
- data/lib/protobuf/rpc/connectors/base.rb +1 -1
- data/lib/protobuf/rpc/connectors/zmq.rb +157 -29
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +49 -0
- data/lib/protobuf/rpc/error/client_error.rb +5 -5
- data/lib/protobuf/rpc/error/server_error.rb +7 -7
- data/lib/protobuf/rpc/rpc.pb.rb +13 -12
- data/lib/protobuf/rpc/servers/evented_runner.rb +11 -6
- data/lib/protobuf/rpc/servers/socket/server.rb +19 -15
- data/lib/protobuf/rpc/servers/socket_runner.rb +21 -18
- data/lib/protobuf/rpc/servers/zmq/broker.rb +104 -94
- data/lib/protobuf/rpc/servers/zmq/server.rb +263 -43
- data/lib/protobuf/rpc/servers/zmq/util.rb +18 -6
- data/lib/protobuf/rpc/servers/zmq/worker.rb +102 -39
- data/lib/protobuf/rpc/servers/zmq_runner.rb +31 -20
- data/lib/protobuf/rpc/service.rb +24 -12
- data/lib/protobuf/rpc/service_directory.rb +206 -0
- data/lib/protobuf/rpc/stat.rb +1 -1
- data/lib/protobuf/version.rb +1 -1
- data/proto/dynamic_discovery.proto +44 -0
- data/spec/benchmark/tasks.rb +1 -3
- data/spec/functional/socket_server_spec.rb +6 -5
- data/spec/functional/zmq_server_spec.rb +59 -30
- data/spec/lib/protobuf/cli_spec.rb +49 -54
- data/spec/lib/protobuf/enum_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/client_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +43 -1
- data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +2 -1
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +9 -8
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +24 -19
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +5 -5
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +183 -0
- data/spec/support/server.rb +21 -12
- data/spec/support/test/resource.pb.rb +6 -0
- data/spec/support/test/resource.proto +5 -0
- data/spec/support/test/resource_service.rb +7 -0
- metadata +11 -11
- data/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +0 -31
data/lib/protobuf/rpc/stat.rb
CHANGED
data/lib/protobuf/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
// Copyright (c) 2013 MoneyDesktop, Inc.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
8
|
+
// furnished to do so, subject to the following conditions:
|
9
|
+
//
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
11
|
+
// all copies or substantial portions of the Software.
|
12
|
+
//
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
// THE SOFTWARE.
|
20
|
+
|
21
|
+
// Authors: Devin Christensen
|
22
|
+
//
|
23
|
+
// Protobufs needed for dynamic discovery zmq server and client.
|
24
|
+
|
25
|
+
package protobuf.rpc.dynamicDiscovery;
|
26
|
+
|
27
|
+
enum BeaconType {
|
28
|
+
HEARTBEAT = 0;
|
29
|
+
FLATLINE = 1;
|
30
|
+
}
|
31
|
+
|
32
|
+
message Server {
|
33
|
+
optional string uuid = 1;
|
34
|
+
optional string address = 2;
|
35
|
+
optional string port = 3;
|
36
|
+
optional int32 ttl = 4;
|
37
|
+
repeated string services = 5;
|
38
|
+
}
|
39
|
+
|
40
|
+
message Beacon {
|
41
|
+
optional BeaconType beacon_type = 1;
|
42
|
+
optional Server server = 2;
|
43
|
+
}
|
44
|
+
|
data/spec/benchmark/tasks.rb
CHANGED
@@ -32,9 +32,7 @@ namespace :benchmark do
|
|
32
32
|
EM.stop if EM.reactor_running?
|
33
33
|
|
34
34
|
EventMachine.fiber_run do
|
35
|
-
StubServer.new do |server|
|
36
|
-
client = ::Test::ResourceService.client
|
37
|
-
|
35
|
+
StubServer.new(:server => Protobuf::Rpc::Evented::Server) do |server|
|
38
36
|
benchmark_wrapper(global_bench) do |bench|
|
39
37
|
bench.report("ES / EC") do
|
40
38
|
(1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) }
|
@@ -4,14 +4,14 @@ require 'spec/support/test/resource_service'
|
|
4
4
|
describe 'Functional Socket Client' do
|
5
5
|
before(:all) do
|
6
6
|
load "protobuf/socket.rb"
|
7
|
-
|
8
|
-
|
9
|
-
@server_thread = Thread.new(
|
10
|
-
Thread.pass until
|
7
|
+
@options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
|
8
|
+
@runner = ::Protobuf::Rpc::SocketRunner.new(@options)
|
9
|
+
@server_thread = Thread.new(@runner) { |runner| runner.run }
|
10
|
+
Thread.pass until @runner.running?
|
11
11
|
end
|
12
12
|
|
13
13
|
after(:all) do
|
14
|
-
|
14
|
+
@runner.stop
|
15
15
|
@server_thread.join
|
16
16
|
end
|
17
17
|
|
@@ -56,3 +56,4 @@ describe 'Functional Socket Client' do
|
|
56
56
|
error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
@@ -1,24 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'spec/support/test/resource_service'
|
3
|
+
require 'protobuf/rpc/service_directory'
|
3
4
|
|
4
5
|
describe 'Functional ZMQ Client' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
let(:options) {{
|
7
|
+
:host => "127.0.0.1",
|
8
|
+
:port => 9399,
|
9
|
+
:worker_port => 9400,
|
10
|
+
:backlog => 100,
|
11
|
+
:threshold => 100,
|
12
|
+
:threads => 5
|
13
|
+
}}
|
14
|
+
|
15
|
+
let(:server) { ::Protobuf::Rpc::Zmq::Server.new(options) }
|
16
|
+
let(:server_thread) { Thread.new(server) { |server| server.run } }
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
before do
|
19
|
+
load "protobuf/zmq.rb"
|
20
|
+
server_thread.abort_on_exception = true
|
21
|
+
Thread.pass until server.running?
|
17
22
|
end
|
18
23
|
|
19
|
-
after
|
20
|
-
|
21
|
-
|
24
|
+
after do
|
25
|
+
server.stop
|
26
|
+
server_thread.join
|
22
27
|
end
|
23
28
|
|
24
29
|
it 'runs fine when required fields are set' do
|
@@ -38,27 +43,51 @@ describe 'Functional ZMQ Client' do
|
|
38
43
|
}.to_not raise_error
|
39
44
|
end
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
context 'when a message is malformed' do
|
47
|
+
it 'calls the on_failure callback' do
|
48
|
+
error = nil
|
49
|
+
StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do
|
50
|
+
request = ::Test::ResourceFindRequest.new(:active => true)
|
51
|
+
client = ::Test::ResourceService.client
|
52
|
+
|
53
|
+
client.find(request) do |c|
|
54
|
+
c.on_success { raise "shouldn't pass" }
|
55
|
+
c.on_failure {|e| error = e }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
error.message.should match(/name.*required/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when the request type is wrong' do
|
63
|
+
it 'calls the on_failure callback' do
|
64
|
+
error = nil
|
65
|
+
StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do
|
66
|
+
request = ::Test::Resource.new(:name => 'Test Name')
|
67
|
+
client = ::Test::ResourceService.client
|
45
68
|
|
46
|
-
|
47
|
-
|
48
|
-
|
69
|
+
client.find(request) do |c|
|
70
|
+
c.on_success { raise "shouldn't pass" }
|
71
|
+
c.on_failure {|e| error = e}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
error.message.should match(/expected request.*ResourceFindRequest.*Resource instead/i)
|
49
75
|
end
|
50
|
-
error.message.should =~ /name.*required/
|
51
76
|
end
|
52
77
|
|
53
|
-
|
54
|
-
error
|
55
|
-
|
56
|
-
|
78
|
+
context 'when the server takes too long to respond' do
|
79
|
+
it 'responds with a timeout error' do
|
80
|
+
error = nil
|
81
|
+
StubServer.new(:server => Protobuf::Rpc::Zmq::Server) do
|
82
|
+
client = ::Test::ResourceService.client(:timeout => 1)
|
57
83
|
|
58
|
-
|
59
|
-
|
60
|
-
|
84
|
+
client.find_with_sleep(:sleep => 2) do |c|
|
85
|
+
c.on_success { raise "shouldn't pass" }
|
86
|
+
c.on_failure { |e| error = e }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
error.message.should match(/The server took longer than 1 seconds to respond/i)
|
61
90
|
end
|
62
|
-
error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i
|
63
91
|
end
|
92
|
+
|
64
93
|
end
|
@@ -7,10 +7,14 @@ describe ::Protobuf::CLI do
|
|
7
7
|
File.expand_path('../../../support/test_app_file.rb', __FILE__)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
let(:sock_runner) { double "SocketRunner", run: nil, register_signals: nil }
|
11
|
+
let(:zmq_runner) { double "ZmqRunner", run: nil, register_signals: nil }
|
12
|
+
let(:evented_runner) { double "EventedRunner", run: nil, register_signals: nil }
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
::Protobuf::Rpc::SocketRunner.stub(:new) { sock_runner }
|
16
|
+
::Protobuf::Rpc::ZmqRunner.stub(:new) { zmq_runner }
|
17
|
+
::Protobuf::Rpc::EventedRunner.stub(:new) { evented_runner }
|
14
18
|
end
|
15
19
|
|
16
20
|
describe '#start' do
|
@@ -22,9 +26,9 @@ describe ::Protobuf::CLI do
|
|
22
26
|
let(:test_args) { [ '--host=123.123.123.123' ] }
|
23
27
|
|
24
28
|
it 'sends the host option to the runner' do
|
25
|
-
::Protobuf::Rpc::SocketRunner.should_receive(:
|
29
|
+
::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options|
|
26
30
|
options[:host].should eq '123.123.123.123'
|
27
|
-
end
|
31
|
+
end.and_return(sock_runner)
|
28
32
|
described_class.start(args)
|
29
33
|
end
|
30
34
|
end
|
@@ -33,9 +37,9 @@ describe ::Protobuf::CLI do
|
|
33
37
|
let(:test_args) { [ '--port=12345' ] }
|
34
38
|
|
35
39
|
it 'sends the port option to the runner' do
|
36
|
-
::Protobuf::Rpc::SocketRunner.should_receive(:
|
40
|
+
::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options|
|
37
41
|
options[:port].should eq 12345
|
38
|
-
end
|
42
|
+
end.and_return(sock_runner)
|
39
43
|
described_class.start(args)
|
40
44
|
end
|
41
45
|
end
|
@@ -44,9 +48,9 @@ describe ::Protobuf::CLI do
|
|
44
48
|
let(:test_args) { [ '--threads=500' ] }
|
45
49
|
|
46
50
|
it 'sends the threads option to the runner' do
|
47
|
-
::Protobuf::Rpc::SocketRunner.should_receive(:
|
51
|
+
::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options|
|
48
52
|
options[:threads].should eq 500
|
49
|
-
end
|
53
|
+
end.and_return(sock_runner)
|
50
54
|
described_class.start(args)
|
51
55
|
end
|
52
56
|
end
|
@@ -55,9 +59,9 @@ describe ::Protobuf::CLI do
|
|
55
59
|
let(:test_args) { [ '--backlog=500' ] }
|
56
60
|
|
57
61
|
it 'sends the backlog option to the runner' do
|
58
|
-
::Protobuf::Rpc::SocketRunner.should_receive(:
|
62
|
+
::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options|
|
59
63
|
options[:backlog].should eq 500
|
60
|
-
end
|
64
|
+
end.and_return(sock_runner)
|
61
65
|
described_class.start(args)
|
62
66
|
end
|
63
67
|
end
|
@@ -66,9 +70,9 @@ describe ::Protobuf::CLI do
|
|
66
70
|
let(:test_args) { [ '--threshold=500' ] }
|
67
71
|
|
68
72
|
it 'sends the backlog option to the runner' do
|
69
|
-
::Protobuf::Rpc::SocketRunner.should_receive(:
|
73
|
+
::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options|
|
70
74
|
options[:threshold].should eq 500
|
71
|
-
end
|
75
|
+
end.and_return(sock_runner)
|
72
76
|
described_class.start(args)
|
73
77
|
end
|
74
78
|
end
|
@@ -83,17 +87,6 @@ describe ::Protobuf::CLI do
|
|
83
87
|
end
|
84
88
|
described_class.start(args)
|
85
89
|
end
|
86
|
-
|
87
|
-
context 'when debugging' do
|
88
|
-
let(:test_args) { [ '--level=3', '--debug' ] }
|
89
|
-
|
90
|
-
it 'overrides the log-level to DEBUG' do
|
91
|
-
::Protobuf::Logger.should_receive(:configure) do |options|
|
92
|
-
options[:level].should eq ::Logger::DEBUG
|
93
|
-
end
|
94
|
-
described_class.start(args)
|
95
|
-
end
|
96
|
-
end
|
97
90
|
end
|
98
91
|
|
99
92
|
context 'gc options' do
|
@@ -103,16 +96,18 @@ describe ::Protobuf::CLI do
|
|
103
96
|
|
104
97
|
it 'sets both request and serialization pausing to false' do
|
105
98
|
described_class.start(args)
|
106
|
-
::Protobuf.
|
99
|
+
::Protobuf.should_not be_gc_pause_server_request
|
107
100
|
end
|
108
101
|
end
|
109
102
|
|
110
|
-
|
111
|
-
|
103
|
+
unless defined?(JRUBY_VERSION)
|
104
|
+
context 'request pausing' do
|
105
|
+
let(:test_args) { [ '--gc_pause_request' ] }
|
112
106
|
|
113
|
-
|
114
|
-
|
115
|
-
|
107
|
+
it 'sets the configuration option to GC pause server request' do
|
108
|
+
described_class.start(args)
|
109
|
+
::Protobuf.should be_gc_pause_server_request
|
110
|
+
end
|
116
111
|
end
|
117
112
|
end
|
118
113
|
end
|
@@ -167,18 +162,18 @@ describe ::Protobuf::CLI do
|
|
167
162
|
let(:runner) { ::Protobuf::Rpc::SocketRunner }
|
168
163
|
|
169
164
|
before do
|
170
|
-
::Protobuf::Rpc::EventedRunner.should_not_receive(:
|
171
|
-
::Protobuf::Rpc::ZmqRunner.should_not_receive(:
|
165
|
+
::Protobuf::Rpc::EventedRunner.should_not_receive(:new)
|
166
|
+
::Protobuf::Rpc::ZmqRunner.should_not_receive(:new)
|
172
167
|
end
|
173
168
|
|
174
169
|
it 'is activated by the --socket switch' do
|
175
|
-
runner.should_receive(:
|
170
|
+
runner.should_receive(:new)
|
176
171
|
described_class.start(args)
|
177
172
|
end
|
178
173
|
|
179
174
|
it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do
|
180
175
|
ENV['PB_SERVER_TYPE'] = "Socket"
|
181
|
-
runner.should_receive(:
|
176
|
+
runner.should_receive(:new).and_return(sock_runner)
|
182
177
|
described_class.start(args)
|
183
178
|
ENV.delete('PB_SERVER_TYPE')
|
184
179
|
end
|
@@ -194,18 +189,18 @@ describe ::Protobuf::CLI do
|
|
194
189
|
let(:runner) { ::Protobuf::Rpc::EventedRunner }
|
195
190
|
|
196
191
|
before do
|
197
|
-
::Protobuf::Rpc::SocketRunner.should_not_receive(:
|
198
|
-
::Protobuf::Rpc::ZmqRunner.should_not_receive(:
|
192
|
+
::Protobuf::Rpc::SocketRunner.should_not_receive(:new)
|
193
|
+
::Protobuf::Rpc::ZmqRunner.should_not_receive(:new)
|
199
194
|
end
|
200
195
|
|
201
196
|
it 'is activated by the --evented switch' do
|
202
|
-
runner.should_receive(:
|
197
|
+
runner.should_receive(:new).and_return(evented_runner)
|
203
198
|
described_class.start(args)
|
204
199
|
end
|
205
200
|
|
206
201
|
it 'is activated by PB_SERVER_TYPE=Evented ENV variable' do
|
207
202
|
ENV['PB_SERVER_TYPE'] = "Evented"
|
208
|
-
runner.should_receive(:
|
203
|
+
runner.should_receive(:new).and_return(evented_runner)
|
209
204
|
described_class.start(args)
|
210
205
|
ENV.delete('PB_SERVER_TYPE')
|
211
206
|
end
|
@@ -215,29 +210,29 @@ describe ::Protobuf::CLI do
|
|
215
210
|
::Protobuf.connector_type.should == :evented
|
216
211
|
end
|
217
212
|
end
|
218
|
-
|
213
|
+
|
219
214
|
context 'zmq workers only' do
|
220
215
|
let(:test_args) { [ '--workers_only', '--zmq' ] }
|
221
216
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
222
217
|
|
223
218
|
before do
|
224
|
-
::Protobuf::Rpc::SocketRunner.should_not_receive(:
|
225
|
-
::Protobuf::Rpc::EventedRunner.should_not_receive(:
|
219
|
+
::Protobuf::Rpc::SocketRunner.should_not_receive(:new)
|
220
|
+
::Protobuf::Rpc::EventedRunner.should_not_receive(:new)
|
226
221
|
end
|
227
222
|
|
228
223
|
it 'is activated by the --workers_only switch' do
|
229
|
-
runner.should_receive(:
|
224
|
+
runner.should_receive(:new) do |options|
|
230
225
|
options[:workers_only].should be_true
|
231
|
-
end
|
226
|
+
end.and_return(zmq_runner)
|
232
227
|
|
233
228
|
described_class.start(args)
|
234
229
|
end
|
235
230
|
|
236
231
|
it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do
|
237
232
|
ENV['PB_WORKERS_ONLY'] = "1"
|
238
|
-
runner.should_receive(:
|
233
|
+
runner.should_receive(:new) do |options|
|
239
234
|
options[:workers_only].should be_true
|
240
|
-
end
|
235
|
+
end.and_return(zmq_runner)
|
241
236
|
|
242
237
|
described_class.start(args)
|
243
238
|
ENV.delete('PB_WORKERS_ONLY')
|
@@ -249,14 +244,14 @@ describe ::Protobuf::CLI do
|
|
249
244
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
250
245
|
|
251
246
|
before do
|
252
|
-
::Protobuf::Rpc::SocketRunner.should_not_receive(:
|
253
|
-
::Protobuf::Rpc::EventedRunner.should_not_receive(:
|
247
|
+
::Protobuf::Rpc::SocketRunner.should_not_receive(:new)
|
248
|
+
::Protobuf::Rpc::EventedRunner.should_not_receive(:new)
|
254
249
|
end
|
255
250
|
|
256
251
|
it 'is activated by the --worker_port switch' do
|
257
|
-
runner.should_receive(:
|
252
|
+
runner.should_receive(:new) do |options|
|
258
253
|
options[:worker_port].should eq(1234)
|
259
|
-
end
|
254
|
+
end.and_return(zmq_runner)
|
260
255
|
|
261
256
|
described_class.start(args)
|
262
257
|
end
|
@@ -267,18 +262,18 @@ describe ::Protobuf::CLI do
|
|
267
262
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
268
263
|
|
269
264
|
before do
|
270
|
-
::Protobuf::Rpc::SocketRunner.should_not_receive(:
|
271
|
-
::Protobuf::Rpc::EventedRunner.should_not_receive(:
|
265
|
+
::Protobuf::Rpc::SocketRunner.should_not_receive(:new)
|
266
|
+
::Protobuf::Rpc::EventedRunner.should_not_receive(:new)
|
272
267
|
end
|
273
268
|
|
274
269
|
it 'is activated by the --zmq switch' do
|
275
|
-
runner.should_receive(:
|
270
|
+
runner.should_receive(:new)
|
276
271
|
described_class.start(args)
|
277
272
|
end
|
278
273
|
|
279
274
|
it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do
|
280
275
|
ENV['PB_SERVER_TYPE'] = "Zmq"
|
281
|
-
runner.should_receive(:
|
276
|
+
runner.should_receive(:new)
|
282
277
|
described_class.start(args)
|
283
278
|
ENV.delete('PB_SERVER_TYPE')
|
284
279
|
end
|