protobuf 3.3.6 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +48 -0
- data/.rubocop_todo.yml +79 -0
- data/.travis.yml +12 -4
- data/Rakefile +14 -11
- data/bin/protoc-gen-ruby +0 -1
- data/bin/rpc_server +1 -0
- data/install-protobuf.sh +8 -0
- data/lib/protobuf.rb +30 -24
- data/lib/protobuf/cli.rb +35 -35
- data/lib/protobuf/code_generator.rb +11 -8
- data/lib/protobuf/decoder.rb +4 -5
- data/lib/protobuf/deprecation.rb +20 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +2 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +2 -0
- data/lib/protobuf/encoder.rb +9 -4
- data/lib/protobuf/enum.rb +38 -54
- data/lib/protobuf/field.rb +2 -2
- data/lib/protobuf/field/base_field.rb +28 -32
- data/lib/protobuf/field/bool_field.rb +4 -4
- data/lib/protobuf/field/bytes_field.rb +5 -4
- data/lib/protobuf/field/double_field.rb +0 -1
- data/lib/protobuf/field/enum_field.rb +4 -7
- data/lib/protobuf/field/field_array.rb +3 -4
- data/lib/protobuf/field/fixed32_field.rb +1 -1
- data/lib/protobuf/field/fixed64_field.rb +0 -1
- data/lib/protobuf/field/float_field.rb +0 -1
- data/lib/protobuf/field/int32_field.rb +0 -1
- data/lib/protobuf/field/int64_field.rb +0 -1
- data/lib/protobuf/field/integer_field.rb +0 -1
- data/lib/protobuf/field/message_field.rb +2 -3
- data/lib/protobuf/field/sfixed32_field.rb +0 -1
- data/lib/protobuf/field/sfixed64_field.rb +0 -1
- data/lib/protobuf/field/signed_integer_field.rb +0 -1
- data/lib/protobuf/field/sint32_field.rb +0 -1
- data/lib/protobuf/field/sint64_field.rb +0 -1
- data/lib/protobuf/field/string_field.rb +0 -1
- data/lib/protobuf/field/uint32_field.rb +0 -1
- data/lib/protobuf/field/uint64_field.rb +0 -1
- data/lib/protobuf/field/varint_field.rb +0 -1
- data/lib/protobuf/generators/base.rb +1 -2
- data/lib/protobuf/generators/enum_generator.rb +1 -2
- data/lib/protobuf/generators/extension_generator.rb +1 -2
- data/lib/protobuf/generators/field_generator.rb +4 -5
- data/lib/protobuf/generators/file_generator.rb +22 -27
- data/lib/protobuf/generators/group_generator.rb +15 -16
- data/lib/protobuf/generators/message_generator.rb +13 -14
- data/lib/protobuf/generators/printable.rb +9 -10
- data/lib/protobuf/generators/service_generator.rb +1 -2
- data/lib/protobuf/lifecycle.rb +20 -33
- data/lib/protobuf/logging.rb +4 -6
- data/lib/protobuf/message.rb +22 -16
- data/lib/protobuf/message/fields.rb +14 -17
- data/lib/protobuf/message/serialization.rb +6 -5
- data/lib/protobuf/rpc/buffer.rb +10 -12
- data/lib/protobuf/rpc/client.rb +12 -12
- data/lib/protobuf/rpc/connectors/base.rb +4 -3
- data/lib/protobuf/rpc/connectors/common.rb +15 -17
- data/lib/protobuf/rpc/connectors/socket.rb +2 -2
- data/lib/protobuf/rpc/connectors/zmq.rb +118 -108
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -0
- data/lib/protobuf/rpc/env.rb +12 -12
- data/lib/protobuf/rpc/error.rb +1 -1
- data/lib/protobuf/rpc/error/client_error.rb +4 -4
- data/lib/protobuf/rpc/error/server_error.rb +6 -6
- data/lib/protobuf/rpc/middleware/exception_handler.rb +1 -1
- data/lib/protobuf/rpc/middleware/logger.rb +3 -3
- data/lib/protobuf/rpc/middleware/request_decoder.rb +5 -5
- data/lib/protobuf/rpc/middleware/response_encoder.rb +3 -3
- data/lib/protobuf/rpc/rpc.pb.rb +2 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +75 -65
- data/lib/protobuf/rpc/servers/socket/worker.rb +2 -2
- data/lib/protobuf/rpc/servers/socket_runner.rb +12 -6
- data/lib/protobuf/rpc/servers/zmq/broker.rb +10 -6
- data/lib/protobuf/rpc/servers/zmq/server.rb +20 -26
- data/lib/protobuf/rpc/servers/zmq/util.rb +7 -7
- data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -7
- data/lib/protobuf/rpc/servers/zmq_runner.rb +14 -3
- data/lib/protobuf/rpc/service.rb +15 -15
- data/lib/protobuf/rpc/service_directory.rb +7 -11
- data/lib/protobuf/rpc/service_dispatcher.rb +3 -3
- data/lib/protobuf/rpc/service_filters.rb +27 -28
- data/lib/protobuf/rpc/stat.rb +4 -7
- data/lib/protobuf/socket.rb +0 -1
- data/lib/protobuf/tasks/compile.rake +2 -2
- data/lib/protobuf/version.rb +1 -1
- data/protobuf.gemspec +20 -4
- data/spec/benchmark/tasks.rb +49 -23
- data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
- data/spec/encoding/all_types_spec.rb +91 -77
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/socket_server_spec.rb +9 -10
- data/spec/functional/zmq_server_spec.rb +21 -19
- data/spec/lib/protobuf/cli_spec.rb +20 -20
- data/spec/lib/protobuf/code_generator_spec.rb +6 -6
- data/spec/lib/protobuf/enum_spec.rb +57 -31
- data/spec/lib/protobuf/field/float_field_spec.rb +2 -2
- data/spec/lib/protobuf/field/int32_field_spec.rb +1 -1
- data/spec/lib/protobuf/field/string_field_spec.rb +7 -8
- data/spec/lib/protobuf/field_spec.rb +3 -6
- data/spec/lib/protobuf/generators/base_spec.rb +6 -6
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +22 -17
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +8 -9
- data/spec/lib/protobuf/generators/field_generator_spec.rb +14 -11
- data/spec/lib/protobuf/generators/file_generator_spec.rb +7 -4
- data/spec/lib/protobuf/generators/service_generator_spec.rb +14 -11
- data/spec/lib/protobuf/lifecycle_spec.rb +9 -4
- data/spec/lib/protobuf/message_spec.rb +63 -35
- data/spec/lib/protobuf/optionable_spec.rb +3 -3
- data/spec/lib/protobuf/rpc/client_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/connector_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +26 -18
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +11 -9
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +7 -7
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +14 -14
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +5 -5
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +9 -7
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +9 -9
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +24 -23
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +84 -51
- data/spec/lib/protobuf/rpc/service_spec.rb +15 -14
- data/spec/lib/protobuf/rpc/stat_spec.rb +1 -1
- data/spec/lib/protobuf_spec.rb +9 -9
- data/spec/spec_helper.rb +7 -19
- data/spec/support/server.rb +29 -59
- data/spec/support/test/defaults.pb.rb +2 -0
- data/spec/support/test/enum.pb.rb +2 -0
- data/spec/support/test/extended.pb.rb +2 -0
- data/spec/support/test/google_unittest_import.pb.rb +2 -0
- data/spec/support/test/google_unittest_import_public.pb.rb +2 -0
- data/spec/support/test/multi_field_extensions.pb.rb +2 -0
- data/spec/support/test/resource.pb.rb +2 -0
- data/spec/support/test/resource_service.rb +17 -20
- metadata +153 -112
- data/lib/protobuf/deprecator.rb +0 -42
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/optionable'
|
3
3
|
|
4
|
-
describe 'Optionable' do
|
4
|
+
RSpec.describe 'Optionable' do
|
5
5
|
|
6
6
|
describe '.set_option' do
|
7
7
|
before(:all) do
|
@@ -13,9 +13,9 @@ describe 'Optionable' do
|
|
13
13
|
it 'stores the given option and value' do
|
14
14
|
expect(OptionableSetOptionTest).to respond_to(:set_option)
|
15
15
|
expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2)
|
16
|
-
expect
|
16
|
+
expect do
|
17
17
|
OptionableSetOptionTest.set_option(:foo, :bar)
|
18
|
-
|
18
|
+
end.to_not raise_error
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'defaults the value to true' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'spec/support/test/resource_service'
|
3
3
|
|
4
|
-
describe Protobuf::Rpc::Client do
|
4
|
+
RSpec.describe Protobuf::Rpc::Client do
|
5
5
|
before(:each) do
|
6
6
|
load 'protobuf/socket.rb'
|
7
7
|
end
|
@@ -55,7 +55,7 @@ describe Protobuf::Rpc::Client do
|
|
55
55
|
it 'should be able to create the correct request object if passed a hash' do
|
56
56
|
client = Test::ResourceService.client
|
57
57
|
expect(client).to receive(:send_request)
|
58
|
-
client.find(
|
58
|
+
client.find(:name => 'Test Name', :active => false)
|
59
59
|
expect(client.options[:request]).to be_a(Test::ResourceFindRequest)
|
60
60
|
expect(client.options[:request].name).to eq('Test Name')
|
61
61
|
expect(client.options[:request].active).to eq(false)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Protobuf::Rpc::Connectors::Base do
|
3
|
+
RSpec.describe Protobuf::Rpc::Connectors::Base do
|
4
4
|
|
5
5
|
let(:options) do
|
6
6
|
{ :timeout => 60 }
|
@@ -10,12 +10,12 @@ describe Protobuf::Rpc::Connectors::Base do
|
|
10
10
|
|
11
11
|
describe "#send_request" do
|
12
12
|
it "raising an error when 'send_request' is not overridden" do
|
13
|
-
expect{ subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/)
|
13
|
+
expect { subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "does not raise error when 'send_request' is overridden" do
|
17
|
-
new_sub = Class.new(subject.class){ def send_request; end }.new(options)
|
18
|
-
expect{ new_sub.send_request }.to_not raise_error
|
17
|
+
new_sub = Class.new(subject.class) { def send_request; end }.new(options)
|
18
|
+
expect { new_sub.send_request }.to_not raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -30,7 +30,7 @@ describe Protobuf::Rpc::Connectors::Base do
|
|
30
30
|
describe '#success_cb' do
|
31
31
|
it 'allows setting the success callback and calling it' do
|
32
32
|
expect(subject.success_cb).to be_nil
|
33
|
-
cb = proc {|res|
|
33
|
+
cb = proc { |res| fail res }
|
34
34
|
subject.success_cb = cb
|
35
35
|
expect(subject.success_cb).to eq(cb)
|
36
36
|
expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb'
|
@@ -40,7 +40,7 @@ describe Protobuf::Rpc::Connectors::Base do
|
|
40
40
|
describe '#failure_cb' do
|
41
41
|
it 'allows setting the failure callback and calling it' do
|
42
42
|
expect(subject.failure_cb).to be_nil
|
43
|
-
cb = proc {|res|
|
43
|
+
cb = proc { |res| fail res }
|
44
44
|
subject.failure_cb = cb
|
45
45
|
expect(subject.failure_cb).to eq(cb)
|
46
46
|
expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/rpc/service'
|
3
3
|
|
4
|
-
describe Protobuf::Rpc::Connectors::Common do
|
4
|
+
RSpec.describe Protobuf::Rpc::Connectors::Common do
|
5
5
|
let(:common_class) do
|
6
6
|
Class.new(Protobuf::Rpc::Connectors::Base) do
|
7
7
|
include Protobuf::Rpc::Connectors::Common
|
@@ -19,7 +19,7 @@ describe Protobuf::Rpc::Connectors::Common do
|
|
19
19
|
specify { expect(subject.respond_to?(:request_caller)).to be true }
|
20
20
|
specify { expect(subject.respond_to?(:data_callback)).to be true }
|
21
21
|
specify { expect(subject.respond_to?(:error)).to be true }
|
22
|
-
specify { expect(subject.respond_to?(:
|
22
|
+
specify { expect(subject.respond_to?(:failure)).to be true }
|
23
23
|
specify { expect(subject.respond_to?(:complete)).to be true }
|
24
24
|
specify { expect(subject.respond_to?(:parse_response)).to be true }
|
25
25
|
specify { expect(subject.respond_to?(:verify_options!)).to be true }
|
@@ -74,18 +74,26 @@ describe Protobuf::Rpc::Connectors::Common do
|
|
74
74
|
let(:method) { :find }
|
75
75
|
let(:request) { '' }
|
76
76
|
let(:client_host) { 'myhost.myservice.com' }
|
77
|
-
let(:subject_options)
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
let(:subject_options) do
|
78
|
+
{
|
79
|
+
:service => service,
|
80
|
+
:method => method,
|
81
|
+
:request => request,
|
82
|
+
:client_host => client_host,
|
83
|
+
}
|
84
|
+
end
|
81
85
|
|
82
|
-
let(:expected)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
let(:expected) do
|
87
|
+
::Protobuf::Socketrpc::Request.new(
|
88
|
+
:service_name => service.name,
|
89
|
+
:method_name => 'find',
|
90
|
+
:request_proto => '',
|
91
|
+
:caller => client_host,
|
92
|
+
)
|
93
|
+
end
|
86
94
|
|
87
95
|
before { allow(subject).to receive(:validate_request_type!).and_return(true) }
|
88
|
-
before { expect(subject).not_to receive(:
|
96
|
+
before { expect(subject).not_to receive(:failure) }
|
89
97
|
|
90
98
|
specify { expect(subject.request_bytes).to eq expected.encode }
|
91
99
|
end
|
@@ -103,7 +111,7 @@ describe Protobuf::Rpc::Connectors::Common do
|
|
103
111
|
end
|
104
112
|
|
105
113
|
it "doesn't set @failure_cb when already defined" do
|
106
|
-
set_cb =
|
114
|
+
set_cb = -> { true }
|
107
115
|
subject.instance_variable_set(:@failure_cb, set_cb)
|
108
116
|
subject.verify_callbacks
|
109
117
|
expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb)
|
@@ -111,7 +119,7 @@ describe Protobuf::Rpc::Connectors::Common do
|
|
111
119
|
end
|
112
120
|
|
113
121
|
it "doesn't set @success_cb when already defined" do
|
114
|
-
set_cb =
|
122
|
+
set_cb = -> { true }
|
115
123
|
subject.instance_variable_set(:@success_cb, set_cb)
|
116
124
|
subject.verify_callbacks
|
117
125
|
expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb)
|
@@ -133,10 +141,10 @@ describe Protobuf::Rpc::Connectors::Common do
|
|
133
141
|
stats = double("Object")
|
134
142
|
allow(stats).to receive(:stop).and_return(true)
|
135
143
|
subject.stats = stats
|
136
|
-
|
144
|
+
some_cb = double("Object")
|
137
145
|
|
138
|
-
subject.instance_variable_set("@#{cb}",
|
139
|
-
expect(
|
146
|
+
subject.instance_variable_set("@#{cb}", some_cb)
|
147
|
+
expect(some_cb).to receive(:call).and_return(true)
|
140
148
|
subject.method(meth).call(*args)
|
141
149
|
end
|
142
150
|
|
@@ -153,8 +161,8 @@ describe Protobuf::Rpc::Connectors::Common do
|
|
153
161
|
|
154
162
|
end
|
155
163
|
|
156
|
-
it_behaves_like("a ConnectorDisposition", :
|
157
|
-
it_behaves_like("a ConnectorDisposition", :
|
164
|
+
it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message")
|
165
|
+
it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message")
|
158
166
|
it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response")
|
159
167
|
it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response")
|
160
168
|
it_behaves_like("a ConnectorDisposition", :complete, "complete_cb")
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/socket'
|
3
3
|
|
4
|
-
shared_examples "a Protobuf Connector" do
|
5
|
-
subject{ described_class.new({}) }
|
4
|
+
RSpec.shared_examples "a Protobuf Connector" do
|
5
|
+
subject { described_class.new({}) }
|
6
6
|
|
7
7
|
context "API" do
|
8
8
|
# Check the API
|
@@ -13,8 +13,8 @@ shared_examples "a Protobuf Connector" do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe Protobuf::Rpc::Connectors::Socket do
|
17
|
-
subject{ described_class.new({}) }
|
16
|
+
RSpec.describe Protobuf::Rpc::Connectors::Socket do
|
17
|
+
subject { described_class.new({}) }
|
18
18
|
|
19
19
|
it_behaves_like "a Protobuf Connector"
|
20
20
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/zmq'
|
3
3
|
|
4
|
-
describe ::Protobuf::Rpc::Connectors::Zmq do
|
4
|
+
RSpec.describe ::Protobuf::Rpc::Connectors::Zmq do
|
5
5
|
subject { described_class.new(options) }
|
6
6
|
|
7
|
-
let(:options)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
let(:options) do
|
8
|
+
{
|
9
|
+
:service => "Test::Service",
|
10
|
+
:method => "find",
|
11
|
+
:timeout => 3,
|
12
|
+
:host => "127.0.0.1",
|
13
|
+
:port => "9400",
|
14
|
+
}
|
15
|
+
end
|
14
16
|
|
15
17
|
let(:socket_double) { double(::ZMQ::Socket, :connect => 0) }
|
16
18
|
let(:zmq_context_double) { double(::ZMQ::Context, :socket => socket_double) }
|
@@ -29,7 +31,7 @@ describe ::Protobuf::Rpc::Connectors::Zmq do
|
|
29
31
|
end
|
30
32
|
|
31
33
|
describe "#lookup_server_uri" do
|
32
|
-
let(:service_directory) { double('ServiceDirectory', :running? => running?
|
34
|
+
let(:service_directory) { double('ServiceDirectory', :running? => running?) }
|
33
35
|
let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) }
|
34
36
|
let(:listings) { [listing] }
|
35
37
|
let(:running?) { true }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Protobuf::Rpc::Middleware::ExceptionHandler do
|
4
|
-
let(:app) {
|
3
|
+
RSpec.describe Protobuf::Rpc::Middleware::ExceptionHandler do
|
4
|
+
let(:app) { proc { |env| env } }
|
5
5
|
let(:env) { Protobuf::Rpc::Env.new }
|
6
6
|
|
7
7
|
subject { described_class.new(app) }
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Protobuf::Rpc::Middleware::Logger do
|
4
|
-
let(:app) {
|
5
|
-
let(:env)
|
3
|
+
RSpec.describe Protobuf::Rpc::Middleware::Logger do
|
4
|
+
let(:app) { proc { |inner_env| inner_env } }
|
5
|
+
let(:env) do
|
6
6
|
Protobuf::Rpc::Env.new(
|
7
7
|
'client_host' => 'client_host.test.co',
|
8
8
|
'encoded_request' => request_wrapper.encode,
|
@@ -16,17 +16,17 @@ describe Protobuf::Rpc::Middleware::Logger do
|
|
16
16
|
'rpc_service' => service_class,
|
17
17
|
'service_name' => service_name,
|
18
18
|
)
|
19
|
-
|
19
|
+
end
|
20
20
|
let(:method_name) { :find }
|
21
21
|
let(:request) { request_type.new(:name => 'required') }
|
22
22
|
let(:request_type) { rpc_method.request_type }
|
23
|
-
let(:request_wrapper)
|
23
|
+
let(:request_wrapper) do
|
24
24
|
Protobuf::Socketrpc::Request.new(
|
25
25
|
:service_name => service_name,
|
26
26
|
:method_name => method_name.to_s,
|
27
|
-
:request_proto => request
|
27
|
+
:request_proto => request,
|
28
28
|
)
|
29
|
-
|
29
|
+
end
|
30
30
|
let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) }
|
31
31
|
let(:response) { rpc_method.response_type.new(:name => 'required') }
|
32
32
|
let(:rpc_method) { service_class.rpcs[method_name] }
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Protobuf::Rpc::Middleware::RequestDecoder do
|
4
|
-
let(:app) {
|
3
|
+
RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do
|
4
|
+
let(:app) { proc { |env| env } }
|
5
5
|
let(:client_host) { 'client_host.test.co' }
|
6
|
-
let(:env)
|
6
|
+
let(:env) do
|
7
7
|
Protobuf::Rpc::Env.new(
|
8
8
|
'encoded_request' => encoded_request,
|
9
|
-
'log_signature' => 'log_signature'
|
9
|
+
'log_signature' => 'log_signature',
|
10
10
|
)
|
11
|
-
|
11
|
+
end
|
12
12
|
let(:encoded_request) { request_wrapper.encode }
|
13
13
|
let(:method_name) { :find }
|
14
14
|
let(:request) { request_type.new(:name => 'required') }
|
15
15
|
let(:request_type) { rpc_method.request_type }
|
16
|
-
let(:request_wrapper)
|
16
|
+
let(:request_wrapper) do
|
17
17
|
Protobuf::Socketrpc::Request.new(
|
18
18
|
:caller => client_host,
|
19
19
|
:service_name => service_name,
|
20
20
|
:method_name => method_name.to_s,
|
21
|
-
:request_proto => request
|
21
|
+
:request_proto => request,
|
22
22
|
)
|
23
|
-
|
23
|
+
end
|
24
24
|
let(:response_type) { rpc_method.response_type }
|
25
25
|
let(:rpc_method) { rpc_service.rpcs[method_name] }
|
26
26
|
let(:rpc_service) { Test::ResourceService }
|
@@ -83,14 +83,14 @@ describe Protobuf::Rpc::Middleware::RequestDecoder do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
context "when the RPC service is not defined" do
|
86
|
-
let(:request_wrapper)
|
86
|
+
let(:request_wrapper) do
|
87
87
|
Protobuf::Socketrpc::Request.new(
|
88
88
|
:caller => client_host,
|
89
89
|
:service_name => 'Foo',
|
90
90
|
:method_name => method_name.to_s,
|
91
|
-
:request_proto => request
|
91
|
+
:request_proto => request,
|
92
92
|
)
|
93
|
-
|
93
|
+
end
|
94
94
|
|
95
95
|
it "raises a bad request data exception" do
|
96
96
|
expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::ServiceNotFound)
|
@@ -98,14 +98,14 @@ describe Protobuf::Rpc::Middleware::RequestDecoder do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
context "when RPC method is not defined" do
|
101
|
-
let(:request_wrapper)
|
101
|
+
let(:request_wrapper) do
|
102
102
|
Protobuf::Socketrpc::Request.new(
|
103
103
|
:caller => client_host,
|
104
104
|
:service_name => service_name,
|
105
105
|
:method_name => 'foo',
|
106
|
-
:request_proto => request
|
106
|
+
:request_proto => request,
|
107
107
|
)
|
108
|
-
|
108
|
+
end
|
109
109
|
|
110
110
|
it "raises a bad request data exception" do
|
111
111
|
expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound)
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Protobuf::Rpc::Middleware::ResponseEncoder do
|
4
|
-
let(:app) {
|
5
|
-
let(:env)
|
3
|
+
RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do
|
4
|
+
let(:app) { proc { |env| env.response = response; env } }
|
5
|
+
let(:env) do
|
6
6
|
Protobuf::Rpc::Env.new(
|
7
7
|
'response_type' => Test::Resource,
|
8
|
-
'log_signature' => 'log_signature'
|
8
|
+
'log_signature' => 'log_signature',
|
9
9
|
)
|
10
|
-
|
10
|
+
end
|
11
11
|
let(:encoded_response) { response_wrapper.encode }
|
12
12
|
let(:response) { Test::Resource.new(:name => 'required') }
|
13
13
|
let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) }
|
@@ -3,7 +3,7 @@ require 'spec/support/test/resource_service'
|
|
3
3
|
require 'protobuf/rpc/servers/socket_runner'
|
4
4
|
require 'protobuf/socket'
|
5
5
|
|
6
|
-
describe Protobuf::Rpc::Socket::Server do
|
6
|
+
RSpec.describe Protobuf::Rpc::Socket::Server do
|
7
7
|
before(:each) do
|
8
8
|
load 'protobuf/socket.rb'
|
9
9
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/rpc/servers/zmq/server'
|
3
3
|
|
4
|
-
describe Protobuf::Rpc::Zmq::Server do
|
4
|
+
RSpec.describe Protobuf::Rpc::Zmq::Server do
|
5
5
|
subject { described_class.new(options) }
|
6
6
|
|
7
|
-
let(:options)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
let(:options) do
|
8
|
+
{
|
9
|
+
:host => '127.0.0.1',
|
10
|
+
:port => 9399,
|
11
|
+
:worker_port => 9400,
|
12
|
+
:workers_only => true,
|
13
|
+
}
|
14
|
+
end
|
13
15
|
|
14
16
|
before do
|
15
17
|
load 'protobuf/zmq.rb'
|
@@ -4,7 +4,7 @@ class UtilTest
|
|
4
4
|
include ::Protobuf::Rpc::Zmq::Util
|
5
5
|
end
|
6
6
|
|
7
|
-
describe ::Protobuf::Rpc::Zmq::Util do
|
7
|
+
RSpec.describe ::Protobuf::Rpc::Zmq::Util do
|
8
8
|
before(:each) do
|
9
9
|
load 'protobuf/zmq.rb'
|
10
10
|
end
|
@@ -12,28 +12,28 @@ describe ::Protobuf::Rpc::Zmq::Util do
|
|
12
12
|
subject { UtilTest.new }
|
13
13
|
describe '#zmq_error_check' do
|
14
14
|
it 'raises when the error code is less than 0' do
|
15
|
-
expect
|
15
|
+
expect do
|
16
16
|
subject.zmq_error_check(-1, :test)
|
17
|
-
|
17
|
+
end.to raise_error(/test/)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'retrieves the error string from ZeroMQ' do
|
21
21
|
allow(ZMQ::Util).to receive(:error_string).and_return('an error from zmq')
|
22
|
-
expect
|
22
|
+
expect do
|
23
23
|
subject.zmq_error_check(-1, :test)
|
24
|
-
|
24
|
+
end.to raise_error(RuntimeError, /an error from zmq/i)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'does nothing if the error code is > 0' do
|
28
|
-
expect
|
28
|
+
expect do
|
29
29
|
subject.zmq_error_check(1, :test)
|
30
|
-
|
30
|
+
end.to_not raise_error
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'does nothing if the error code is == 0' do
|
34
|
-
expect
|
34
|
+
expect do
|
35
35
|
subject.zmq_error_check(0, :test)
|
36
|
-
|
36
|
+
end.to_not raise_error
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|