protobuffy 3.6.0 → 4.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +67 -0
- data/.rubocop_todo.yml +145 -0
- data/.travis.yml +25 -5
- data/CHANGES.md +55 -0
- data/CONTRIBUTING.md +1 -1
- data/LICENSE.txt +17 -9
- data/README.md +13 -12
- data/Rakefile +15 -11
- data/bin/protoc-gen-ruby +8 -3
- data/bin/rpc_server +1 -0
- data/examples/lib/example/reverse-client.rb +2 -2
- data/install-protobuf.sh +28 -0
- data/lib/protobuf.rb +57 -53
- data/lib/protobuf/cli.rb +94 -74
- data/lib/protobuf/code_generator.rb +60 -9
- data/lib/protobuf/decoder.rb +19 -65
- data/lib/protobuf/deprecation.rb +117 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +11 -1
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +55 -3
- data/lib/protobuf/encoder.rb +13 -53
- data/lib/protobuf/enum.rb +58 -63
- data/lib/protobuf/field.rb +4 -4
- data/lib/protobuf/field/base_field.rb +101 -173
- data/lib/protobuf/field/bool_field.rb +17 -11
- data/lib/protobuf/field/bytes_field.rb +21 -35
- data/lib/protobuf/field/double_field.rb +0 -1
- data/lib/protobuf/field/enum_field.rb +23 -22
- data/lib/protobuf/field/field_array.rb +5 -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 +4 -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 +13 -28
- 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 +2 -4
- 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 +30 -13
- data/lib/protobuf/generators/base.rb +30 -16
- data/lib/protobuf/generators/enum_generator.rb +6 -9
- data/lib/protobuf/generators/extension_generator.rb +1 -2
- data/lib/protobuf/generators/field_generator.rb +25 -13
- data/lib/protobuf/generators/file_generator.rb +157 -35
- data/lib/protobuf/generators/group_generator.rb +22 -17
- data/lib/protobuf/generators/message_generator.rb +13 -14
- data/lib/protobuf/generators/option_generator.rb +17 -0
- data/lib/protobuf/generators/printable.rb +12 -13
- data/lib/protobuf/generators/service_generator.rb +2 -3
- data/lib/protobuf/http.rb +2 -2
- data/lib/protobuf/lifecycle.rb +20 -33
- data/lib/protobuf/logging.rb +39 -0
- data/lib/protobuf/message.rb +114 -47
- data/lib/protobuf/message/fields.rb +170 -88
- data/lib/protobuf/message/serialization.rb +19 -18
- data/lib/protobuf/optionable.rb +53 -6
- data/lib/protobuf/rpc/buffer.rb +18 -19
- data/lib/protobuf/rpc/client.rb +22 -50
- data/lib/protobuf/rpc/connectors/base.rb +177 -12
- data/lib/protobuf/rpc/connectors/http.rb +14 -9
- data/lib/protobuf/rpc/connectors/ping.rb +89 -0
- data/lib/protobuf/rpc/connectors/socket.rb +13 -8
- data/lib/protobuf/rpc/connectors/zmq.rb +178 -73
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +4 -1
- data/lib/protobuf/rpc/env.rb +12 -12
- data/lib/protobuf/rpc/error.rb +3 -3
- data/lib/protobuf/rpc/error/client_error.rb +4 -4
- data/lib/protobuf/rpc/error/server_error.rb +9 -9
- data/lib/protobuf/rpc/middleware/exception_handler.rb +6 -2
- data/lib/protobuf/rpc/middleware/logger.rb +8 -4
- data/lib/protobuf/rpc/middleware/request_decoder.rb +17 -21
- data/lib/protobuf/rpc/middleware/response_encoder.rb +22 -27
- data/lib/protobuf/rpc/middleware/statsd.rb +3 -3
- data/lib/protobuf/rpc/rpc.pb.rb +4 -1
- data/lib/protobuf/rpc/server.rb +1 -1
- data/lib/protobuf/rpc/servers/http/server.rb +19 -17
- data/lib/protobuf/rpc/servers/socket/server.rb +78 -70
- data/lib/protobuf/rpc/servers/socket/worker.rb +4 -4
- data/lib/protobuf/rpc/servers/socket_runner.rb +27 -15
- data/lib/protobuf/rpc/servers/zmq/broker.rb +70 -31
- data/lib/protobuf/rpc/servers/zmq/server.rb +55 -47
- data/lib/protobuf/rpc/servers/zmq/util.rb +14 -13
- data/lib/protobuf/rpc/servers/zmq/worker.rb +16 -16
- data/lib/protobuf/rpc/servers/zmq_runner.rb +26 -7
- data/lib/protobuf/rpc/service.rb +21 -27
- data/lib/protobuf/rpc/service_directory.rb +43 -27
- data/lib/protobuf/rpc/service_dispatcher.rb +9 -10
- data/lib/protobuf/rpc/service_filters.rb +32 -55
- data/lib/protobuf/rpc/stat.rb +4 -8
- data/lib/protobuf/socket.rb +1 -2
- data/lib/protobuf/tasks/compile.rake +3 -4
- data/lib/protobuf/varint.rb +9 -0
- data/lib/protobuf/varint_pure.rb +13 -0
- data/lib/protobuf/version.rb +1 -1
- data/lib/protobuf/zmq.rb +2 -2
- data/proto/google/protobuf/descriptor.proto +190 -31
- data/protobuffy.gemspec +30 -17
- data/spec/benchmark/tasks.rb +27 -19
- data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
- data/spec/encoding/all_types_spec.rb +96 -84
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/class_inheritance_spec.rb +52 -0
- data/spec/functional/code_generator_spec.rb +38 -0
- data/spec/functional/socket_server_spec.rb +15 -15
- data/spec/functional/zmq_server_spec.rb +29 -27
- data/spec/lib/protobuf/cli_spec.rb +82 -67
- data/spec/lib/protobuf/code_generator_spec.rb +37 -10
- data/spec/lib/protobuf/enum_spec.rb +77 -46
- data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
- data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/enum_field_spec.rb +26 -0
- data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
- data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
- data/spec/lib/protobuf/field/int32_field_spec.rb +114 -1
- data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
- data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +44 -11
- data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field_spec.rb +4 -6
- data/spec/lib/protobuf/generators/base_spec.rb +80 -13
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +35 -21
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +12 -13
- data/spec/lib/protobuf/generators/field_generator_spec.rb +73 -21
- data/spec/lib/protobuf/generators/file_generator_spec.rb +89 -6
- data/spec/lib/protobuf/generators/service_generator_spec.rb +25 -13
- data/spec/lib/protobuf/lifecycle_spec.rb +25 -20
- data/spec/lib/protobuf/message_spec.rb +578 -79
- data/spec/lib/protobuf/optionable_spec.rb +202 -26
- data/spec/lib/protobuf/rpc/client_spec.rb +16 -16
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +167 -13
- data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +4 -5
- data/spec/lib/protobuf/rpc/connectors/http_spec.rb +13 -11
- data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +6 -7
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +35 -52
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +10 -10
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +11 -11
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +23 -23
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +11 -11
- data/spec/lib/protobuf/rpc/middleware/statsd_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +47 -44
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +12 -10
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +11 -11
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +7 -7
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +47 -49
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +8 -25
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +102 -69
- data/spec/lib/protobuf/rpc/service_spec.rb +37 -36
- data/spec/lib/protobuf/rpc/stat_spec.rb +7 -9
- data/spec/lib/protobuf/varint_spec.rb +29 -0
- data/spec/lib/protobuf_spec.rb +55 -28
- data/spec/spec_helper.rb +12 -27
- data/spec/support/all.rb +0 -1
- data/spec/support/packed_field.rb +4 -3
- data/spec/support/{test → protos}/all_types.data.bin +0 -0
- data/spec/support/{test → protos}/all_types.data.txt +0 -0
- data/spec/support/{test → protos}/enum.pb.rb +8 -4
- data/spec/support/{test → protos}/enum.proto +4 -1
- data/spec/support/{test → protos}/extreme_values.data.bin +0 -0
- data/spec/support/protos/google_unittest.bin +0 -0
- data/spec/support/protos/google_unittest.pb.rb +798 -0
- data/spec/support/{test → protos}/google_unittest.proto +237 -66
- data/spec/support/protos/google_unittest_custom_options.bin +0 -0
- data/spec/support/protos/google_unittest_custom_options.pb.rb +268 -0
- data/spec/support/protos/google_unittest_custom_options.proto +424 -0
- data/spec/support/protos/google_unittest_import.pb.rb +55 -0
- data/spec/support/{test → protos}/google_unittest_import.proto +19 -10
- data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
- data/spec/support/{test → protos}/google_unittest_import_public.proto +8 -5
- data/spec/support/{test → protos}/multi_field_extensions.pb.rb +5 -2
- data/spec/support/{test → protos}/multi_field_extensions.proto +2 -0
- data/spec/support/{test → protos}/resource.pb.rb +47 -11
- data/spec/support/{test → protos}/resource.proto +24 -1
- data/spec/support/resource_service.rb +23 -0
- data/spec/support/server.rb +32 -61
- metadata +119 -59
- data/lib/protobuf/deprecator.rb +0 -42
- data/lib/protobuf/logger.rb +0 -93
- data/lib/protobuf/rpc/connector.rb +0 -21
- data/lib/protobuf/rpc/connectors/common.rb +0 -172
- data/spec/data/data.bin +0 -3
- data/spec/data/types.bin +0 -0
- data/spec/lib/protobuf/logger_spec.rb +0 -145
- data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
- data/spec/support/test/defaults.pb.rb +0 -25
- data/spec/support/test/defaults.proto +0 -9
- data/spec/support/test/extended.pb.rb +0 -22
- data/spec/support/test/extended.proto +0 -10
- data/spec/support/test/google_unittest.pb.rb +0 -543
- data/spec/support/test/google_unittest_import.pb.rb +0 -37
- data/spec/support/test/google_unittest_import_public.pb.rb +0 -8
- data/spec/support/test/resource_service.rb +0 -26
- data/spec/support/tolerance_matcher.rb +0 -40
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: binary
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'protobuf/code_generator'
|
5
|
+
|
6
|
+
RSpec.describe 'code generation' do
|
7
|
+
it "generates code for google's unittest.proto" do
|
8
|
+
bytes = IO.read(PROTOS_PATH.join('google_unittest.bin'), :mode => 'rb')
|
9
|
+
|
10
|
+
expected_files =
|
11
|
+
["google_unittest_import_public.pb.rb", "google_unittest_import.pb.rb", "google_unittest.pb.rb"]
|
12
|
+
|
13
|
+
expected_file_descriptors = expected_files.map do |file_name|
|
14
|
+
file_content = File.open(PROTOS_PATH.join(file_name), "r:UTF-8", &:read)
|
15
|
+
::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(
|
16
|
+
:name => "protos/" + file_name, :content => file_content)
|
17
|
+
end
|
18
|
+
|
19
|
+
expected_output =
|
20
|
+
::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => expected_file_descriptors)
|
21
|
+
|
22
|
+
code_generator = ::Protobuf::CodeGenerator.new(bytes)
|
23
|
+
code_generator.eval_unknown_extensions!
|
24
|
+
expect(code_generator.response_bytes).to eq(expected_output)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "generates code (including service stubs) with custom field and method options" do
|
28
|
+
expected_unittest_custom_options =
|
29
|
+
File.open(PROTOS_PATH.join('google_unittest_custom_options.pb.rb'), "r:UTF-8", &:read)
|
30
|
+
|
31
|
+
bytes = IO.read(PROTOS_PATH.join('google_unittest_custom_options.bin'), :mode => 'rb')
|
32
|
+
code_generator = ::Protobuf::CodeGenerator.new(bytes)
|
33
|
+
code_generator.eval_unknown_extensions!
|
34
|
+
response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(code_generator.response_bytes)
|
35
|
+
expect(response.file.find { |f| f.name == 'protos/google_unittest_custom_options.pb.rb' }.content)
|
36
|
+
.to eq(expected_unittest_custom_options)
|
37
|
+
end
|
38
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require SUPPORT_PATH.join('resource_service')
|
3
3
|
|
4
|
-
describe 'Functional Socket Client' do
|
4
|
+
RSpec.describe 'Functional Socket Client' do
|
5
5
|
before(:all) do
|
6
6
|
load "protobuf/socket.rb"
|
7
7
|
@options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
|
8
8
|
@runner = ::Protobuf::Rpc::SocketRunner.new(@options)
|
9
|
-
@server_thread = Thread.new(@runner
|
9
|
+
@server_thread = Thread.new(@runner, &:run)
|
10
10
|
Thread.pass until @runner.running?
|
11
11
|
end
|
12
12
|
|
@@ -16,20 +16,20 @@ describe 'Functional Socket Client' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'runs fine when required fields are set' do
|
19
|
-
expect
|
19
|
+
expect do
|
20
20
|
client = ::Test::ResourceService.client
|
21
21
|
|
22
22
|
client.find(:name => 'Test Name', :active => true) do |c|
|
23
23
|
c.on_success do |succ|
|
24
|
-
succ.name.
|
25
|
-
succ.status.
|
24
|
+
expect(succ.name).to eq("Test Name")
|
25
|
+
expect(succ.status).to eq(::Test::StatusType::ENABLED)
|
26
26
|
end
|
27
27
|
|
28
28
|
c.on_failure do |err|
|
29
|
-
|
29
|
+
fail err.inspect
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
end.to_not raise_error
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'calls the on_failure callback when a message is malformed' do
|
@@ -38,10 +38,11 @@ describe 'Functional Socket Client' do
|
|
38
38
|
client = ::Test::ResourceService.client
|
39
39
|
|
40
40
|
client.find(request) do |c|
|
41
|
-
c.on_success {
|
42
|
-
c.on_failure {|e| error = e}
|
41
|
+
c.on_success { fail "shouldn't pass" }
|
42
|
+
c.on_failure { |e| error = e }
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
|
+
expect(error.message).to match(/Required field.*does not have a value/)
|
45
46
|
end
|
46
47
|
|
47
48
|
it 'calls the on_failure callback when the request type is wrong' do
|
@@ -50,10 +51,9 @@ describe 'Functional Socket Client' do
|
|
50
51
|
client = ::Test::ResourceService.client
|
51
52
|
|
52
53
|
client.find(request) do |c|
|
53
|
-
c.on_success {
|
54
|
-
c.on_failure {|e| error = e}
|
54
|
+
c.on_success { fail "shouldn't pass" }
|
55
|
+
c.on_failure { |e| error = e }
|
55
56
|
end
|
56
|
-
error.message.
|
57
|
+
expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i)
|
57
58
|
end
|
58
59
|
end
|
59
|
-
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'spec/support/test/resource_service'
|
4
3
|
require 'protobuf/rpc/service_directory'
|
4
|
+
require SUPPORT_PATH.join('resource_service')
|
5
5
|
|
6
|
-
describe 'Functional ZMQ Client' do
|
6
|
+
RSpec.describe 'Functional ZMQ Client' do
|
7
7
|
before(:all) do
|
8
8
|
load "protobuf/zmq.rb"
|
9
|
-
@runner = ::Protobuf::Rpc::ZmqRunner.new(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
@runner = ::Protobuf::Rpc::ZmqRunner.new(
|
10
|
+
'host' => '127.0.0.1',
|
11
|
+
'port' => 9399,
|
12
|
+
'worker_port' => 9408,
|
13
|
+
'backlog' => 100,
|
14
|
+
'threshold' => 100,
|
15
|
+
'threads' => 5
|
16
|
+
)
|
17
|
+
@server_thread = Thread.new(@runner, &:run)
|
16
18
|
Thread.pass until @runner.running?
|
17
19
|
end
|
18
20
|
|
@@ -22,36 +24,36 @@ describe 'Functional ZMQ Client' do
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'runs fine when required fields are set' do
|
25
|
-
expect
|
27
|
+
expect do
|
26
28
|
client = ::Test::ResourceService.client
|
27
29
|
|
28
30
|
client.find(:name => 'Test Name', :active => true) do |c|
|
29
31
|
c.on_success do |succ|
|
30
|
-
succ.name.
|
31
|
-
succ.status.
|
32
|
+
expect(succ.name).to eq("Test Name")
|
33
|
+
expect(succ.status).to eq(::Test::StatusType::ENABLED)
|
32
34
|
end
|
33
35
|
|
34
36
|
c.on_failure do |err|
|
35
|
-
|
37
|
+
fail err.inspect
|
36
38
|
end
|
37
39
|
end
|
38
|
-
|
40
|
+
end.to_not raise_error
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'runs under heavy load' do
|
42
|
-
10.times do
|
43
|
-
5.times.map do
|
44
|
+
10.times do
|
45
|
+
5.times.map do
|
44
46
|
Thread.new do
|
45
47
|
client = ::Test::ResourceService.client
|
46
48
|
|
47
49
|
client.find(:name => 'Test Name', :active => true) do |c|
|
48
50
|
c.on_success do |succ|
|
49
|
-
succ.name.
|
50
|
-
succ.status.
|
51
|
+
expect(succ.name).to eq("Test Name")
|
52
|
+
expect(succ.status).to eq(::Test::StatusType::ENABLED)
|
51
53
|
end
|
52
54
|
|
53
55
|
c.on_failure do |err|
|
54
|
-
|
56
|
+
fail err.inspect
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -66,10 +68,10 @@ describe 'Functional ZMQ Client' do
|
|
66
68
|
client = ::Test::ResourceService.client
|
67
69
|
|
68
70
|
client.find(request) do |c|
|
69
|
-
c.on_success {
|
70
|
-
c.on_failure {|e| error = e }
|
71
|
+
c.on_success { fail "shouldn't pass" }
|
72
|
+
c.on_failure { |e| error = e }
|
71
73
|
end
|
72
|
-
error.message.
|
74
|
+
expect(error.message).to match(/Required field.*does not have a value/)
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -80,10 +82,10 @@ describe 'Functional ZMQ Client' do
|
|
80
82
|
client = ::Test::ResourceService.client
|
81
83
|
|
82
84
|
client.find(request) do |c|
|
83
|
-
c.on_success {
|
84
|
-
c.on_failure {|e| error = e}
|
85
|
+
c.on_success { fail "shouldn't pass" }
|
86
|
+
c.on_failure { |e| error = e }
|
85
87
|
end
|
86
|
-
error.message.
|
88
|
+
expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i)
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
@@ -93,10 +95,10 @@ describe 'Functional ZMQ Client' do
|
|
93
95
|
client = ::Test::ResourceService.client(:timeout => 1)
|
94
96
|
|
95
97
|
client.find_with_sleep(:sleep => 2) do |c|
|
96
|
-
c.on_success {
|
98
|
+
c.on_success { fail "shouldn't pass" }
|
97
99
|
c.on_failure { |e| error = e }
|
98
100
|
end
|
99
|
-
error.message.
|
101
|
+
expect(error.message).to match(/The server repeatedly failed to respond/)
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
@@ -1,96 +1,102 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/cli'
|
3
3
|
|
4
|
-
describe ::Protobuf::CLI do
|
4
|
+
RSpec.describe ::Protobuf::CLI do
|
5
5
|
|
6
6
|
let(:app_file) do
|
7
7
|
File.expand_path('../../../support/test_app_file.rb', __FILE__)
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:sock_runner)
|
10
|
+
let(:sock_runner) do
|
11
11
|
runner = double("SocketRunner", :register_signals => nil)
|
12
|
-
runner.
|
12
|
+
allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind"))
|
13
13
|
runner
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
|
-
let(:zmq_runner)
|
17
|
-
runner = double
|
18
|
-
runner.
|
16
|
+
let(:zmq_runner) do
|
17
|
+
runner = double("ZmqRunner", :register_signals => nil)
|
18
|
+
allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind"))
|
19
19
|
runner
|
20
|
-
|
20
|
+
end
|
21
|
+
|
22
|
+
around(:each) do |example|
|
23
|
+
logger = ::Protobuf::Logging.logger
|
24
|
+
example.run
|
25
|
+
::Protobuf::Logging.logger = logger
|
26
|
+
end
|
21
27
|
|
22
28
|
before(:each) do
|
23
|
-
::Protobuf::Rpc::SocketRunner.
|
24
|
-
::Protobuf::Rpc::ZmqRunner.
|
29
|
+
allow(::Protobuf::Rpc::SocketRunner).to receive(:new).and_return(sock_runner)
|
30
|
+
allow(::Protobuf::Rpc::ZmqRunner).to receive(:new).and_return(zmq_runner)
|
25
31
|
end
|
26
32
|
|
27
33
|
describe '#start' do
|
28
|
-
let(:base_args) { [
|
34
|
+
let(:base_args) { ['start', app_file] }
|
29
35
|
let(:test_args) { [] }
|
30
36
|
let(:args) { base_args + test_args }
|
31
37
|
|
32
38
|
context 'host option' do
|
33
|
-
let(:test_args) { [
|
39
|
+
let(:test_args) { ['--host=123.123.123.123'] }
|
34
40
|
|
35
41
|
it 'sends the host option to the runner' do
|
36
|
-
::Protobuf::Rpc::SocketRunner.
|
37
|
-
options[:host].
|
42
|
+
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
43
|
+
expect(options[:host]).to eq '123.123.123.123'
|
38
44
|
end.and_return(sock_runner)
|
39
45
|
described_class.start(args)
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
43
49
|
context 'port option' do
|
44
|
-
let(:test_args) { [
|
50
|
+
let(:test_args) { ['--port=12345'] }
|
45
51
|
|
46
52
|
it 'sends the port option to the runner' do
|
47
|
-
::Protobuf::Rpc::SocketRunner.
|
48
|
-
options[:port].
|
53
|
+
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
54
|
+
expect(options[:port]).to eq 12345
|
49
55
|
end.and_return(sock_runner)
|
50
56
|
described_class.start(args)
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
60
|
context 'threads option' do
|
55
|
-
let(:test_args) { [
|
61
|
+
let(:test_args) { ['--threads=500'] }
|
56
62
|
|
57
63
|
it 'sends the threads option to the runner' do
|
58
|
-
::Protobuf::Rpc::SocketRunner.
|
59
|
-
options[:threads].
|
64
|
+
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
65
|
+
expect(options[:threads]).to eq 500
|
60
66
|
end.and_return(sock_runner)
|
61
67
|
described_class.start(args)
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
71
|
context 'backlog option' do
|
66
|
-
let(:test_args) { [
|
72
|
+
let(:test_args) { ['--backlog=500'] }
|
67
73
|
|
68
74
|
it 'sends the backlog option to the runner' do
|
69
|
-
::Protobuf::Rpc::SocketRunner.
|
70
|
-
options[:backlog].
|
75
|
+
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
76
|
+
expect(options[:backlog]).to eq 500
|
71
77
|
end.and_return(sock_runner)
|
72
78
|
described_class.start(args)
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
82
|
context 'threshold option' do
|
77
|
-
let(:test_args) { [
|
83
|
+
let(:test_args) { ['--threshold=500'] }
|
78
84
|
|
79
85
|
it 'sends the backlog option to the runner' do
|
80
|
-
::Protobuf::Rpc::SocketRunner.
|
81
|
-
options[:threshold].
|
86
|
+
expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options|
|
87
|
+
expect(options[:threshold]).to eq 500
|
82
88
|
end.and_return(sock_runner)
|
83
89
|
described_class.start(args)
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
87
93
|
context 'log options' do
|
88
|
-
let(:test_args) { [
|
94
|
+
let(:test_args) { ['--log=mylog.log', '--level=0'] }
|
89
95
|
|
90
96
|
it 'sends the log file and level options to the runner' do
|
91
|
-
::Protobuf::
|
92
|
-
|
93
|
-
|
97
|
+
expect(::Protobuf::Logging).to receive(:initialize_logger) do |file, level|
|
98
|
+
expect(file).to eq 'mylog.log'
|
99
|
+
expect(level).to eq 0
|
94
100
|
end
|
95
101
|
described_class.start(args)
|
96
102
|
end
|
@@ -103,17 +109,17 @@ describe ::Protobuf::CLI do
|
|
103
109
|
|
104
110
|
it 'sets both request and serialization pausing to false' do
|
105
111
|
described_class.start(args)
|
106
|
-
::Protobuf.
|
112
|
+
expect(::Protobuf).to_not be_gc_pause_server_request
|
107
113
|
end
|
108
114
|
end
|
109
115
|
|
110
116
|
unless defined?(JRUBY_VERSION)
|
111
117
|
context 'request pausing' do
|
112
|
-
let(:test_args) { [
|
118
|
+
let(:test_args) { ['--gc_pause_request'] }
|
113
119
|
|
114
120
|
it 'sets the configuration option to GC pause server request' do
|
115
121
|
described_class.start(args)
|
116
|
-
::Protobuf.
|
122
|
+
expect(::Protobuf).to be_gc_pause_server_request
|
117
123
|
end
|
118
124
|
end
|
119
125
|
end
|
@@ -128,7 +134,7 @@ describe ::Protobuf::CLI do
|
|
128
134
|
|
129
135
|
it 'sets the deprecation warning flag to true' do
|
130
136
|
described_class.start(args)
|
131
|
-
::Protobuf.print_deprecation_warnings
|
137
|
+
expect(::Protobuf.print_deprecation_warnings?).to be true
|
132
138
|
end
|
133
139
|
end
|
134
140
|
|
@@ -138,69 +144,83 @@ describe ::Protobuf::CLI do
|
|
138
144
|
|
139
145
|
it 'sets the deprecation warning flag to false ' do
|
140
146
|
described_class.start(args)
|
141
|
-
::Protobuf.print_deprecation_warnings
|
147
|
+
expect(::Protobuf.print_deprecation_warnings?).to be false
|
142
148
|
end
|
143
149
|
end
|
144
150
|
end
|
145
151
|
|
146
152
|
context 'when enabled' do
|
147
|
-
let(:test_args) { [
|
153
|
+
let(:test_args) { ['--print_deprecation_warnings'] }
|
148
154
|
|
149
155
|
it 'sets the deprecation warning flag to true' do
|
150
156
|
described_class.start(args)
|
151
|
-
::Protobuf.print_deprecation_warnings
|
157
|
+
expect(::Protobuf.print_deprecation_warnings?).to be true
|
152
158
|
end
|
153
159
|
end
|
154
160
|
|
155
161
|
context 'when disabled' do
|
156
|
-
let(:test_args) { [
|
162
|
+
let(:test_args) { ['--no-print_deprecation_warnings'] }
|
157
163
|
|
158
164
|
it 'sets the deprecation warning flag to false' do
|
159
165
|
described_class.start(args)
|
160
|
-
::Protobuf.print_deprecation_warnings
|
166
|
+
expect(::Protobuf.print_deprecation_warnings?).to be false
|
161
167
|
end
|
162
168
|
end
|
163
169
|
end
|
164
170
|
|
165
171
|
context 'run modes' do
|
166
172
|
|
173
|
+
context "extension" do
|
174
|
+
let(:runner) { ::Protobuf::Rpc::Servers::SocketRunner }
|
175
|
+
|
176
|
+
it "loads the runner specified by PB_SERVER_TYPE" do
|
177
|
+
ENV['PB_SERVER_TYPE'] = "protobuf/rpc/servers/socket_runner"
|
178
|
+
expect(runner).to receive(:new).and_return(sock_runner)
|
179
|
+
described_class.start(args)
|
180
|
+
ENV.delete('PB_SERVER_TYPE')
|
181
|
+
end
|
182
|
+
|
183
|
+
context "without extension loaded" do
|
184
|
+
it "will throw a LoadError when extension is not loaded" do
|
185
|
+
ENV['PB_SERVER_TYPE'] = "socket_to_load"
|
186
|
+
expect { described_class.start(args) }.to raise_error(LoadError, /socket_to_load/)
|
187
|
+
ENV.delete("PB_SERVER_TYPE")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
167
192
|
context 'socket' do
|
168
|
-
let(:test_args) { [
|
193
|
+
let(:test_args) { ['--socket'] }
|
169
194
|
let(:runner) { ::Protobuf::Rpc::SocketRunner }
|
170
195
|
|
171
196
|
before do
|
172
|
-
::Protobuf::Rpc::ZmqRunner.
|
197
|
+
expect(::Protobuf::Rpc::ZmqRunner).not_to receive(:new)
|
173
198
|
end
|
174
199
|
|
175
200
|
it 'is activated by the --socket switch' do
|
176
|
-
runner.
|
201
|
+
expect(runner).to receive(:new)
|
177
202
|
described_class.start(args)
|
178
203
|
end
|
179
204
|
|
180
205
|
it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do
|
181
206
|
ENV['PB_SERVER_TYPE'] = "Socket"
|
182
|
-
runner.
|
207
|
+
expect(runner).to receive(:new).and_return(sock_runner)
|
183
208
|
described_class.start(args)
|
184
209
|
ENV.delete('PB_SERVER_TYPE')
|
185
210
|
end
|
186
|
-
|
187
|
-
it 'configures the connector type to be socket' do
|
188
|
-
load "protobuf/socket.rb"
|
189
|
-
::Protobuf.connector_type.should == :socket
|
190
|
-
end
|
191
211
|
end
|
192
212
|
|
193
213
|
context 'zmq workers only' do
|
194
|
-
let(:test_args) { [
|
214
|
+
let(:test_args) { ['--workers_only', '--zmq'] }
|
195
215
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
196
216
|
|
197
217
|
before do
|
198
|
-
::Protobuf::Rpc::SocketRunner.
|
218
|
+
expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new)
|
199
219
|
end
|
200
220
|
|
201
221
|
it 'is activated by the --workers_only switch' do
|
202
|
-
runner.
|
203
|
-
options[:workers_only].
|
222
|
+
expect(runner).to receive(:new) do |options|
|
223
|
+
expect(options[:workers_only]).to be true
|
204
224
|
end.and_return(zmq_runner)
|
205
225
|
|
206
226
|
described_class.start(args)
|
@@ -208,8 +228,8 @@ describe ::Protobuf::CLI do
|
|
208
228
|
|
209
229
|
it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do
|
210
230
|
ENV['PB_WORKERS_ONLY'] = "1"
|
211
|
-
runner.
|
212
|
-
options[:workers_only].
|
231
|
+
expect(runner).to receive(:new) do |options|
|
232
|
+
expect(options[:workers_only]).to be true
|
213
233
|
end.and_return(zmq_runner)
|
214
234
|
|
215
235
|
described_class.start(args)
|
@@ -218,16 +238,16 @@ describe ::Protobuf::CLI do
|
|
218
238
|
end
|
219
239
|
|
220
240
|
context 'zmq worker port' do
|
221
|
-
let(:test_args) { [
|
241
|
+
let(:test_args) { ['--worker_port=1234', '--zmq'] }
|
222
242
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
223
243
|
|
224
244
|
before do
|
225
|
-
::Protobuf::Rpc::SocketRunner.
|
245
|
+
expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new)
|
226
246
|
end
|
227
247
|
|
228
248
|
it 'is activated by the --worker_port switch' do
|
229
|
-
runner.
|
230
|
-
options[:worker_port].
|
249
|
+
expect(runner).to receive(:new) do |options|
|
250
|
+
expect(options[:worker_port]).to eq(1234)
|
231
251
|
end.and_return(zmq_runner)
|
232
252
|
|
233
253
|
described_class.start(args)
|
@@ -235,29 +255,24 @@ describe ::Protobuf::CLI do
|
|
235
255
|
end
|
236
256
|
|
237
257
|
context 'zmq' do
|
238
|
-
let(:test_args) { [
|
258
|
+
let(:test_args) { ['--zmq'] }
|
239
259
|
let(:runner) { ::Protobuf::Rpc::ZmqRunner }
|
240
260
|
|
241
261
|
before do
|
242
|
-
::Protobuf::Rpc::SocketRunner.
|
262
|
+
expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new)
|
243
263
|
end
|
244
264
|
|
245
265
|
it 'is activated by the --zmq switch' do
|
246
|
-
runner.
|
266
|
+
expect(runner).to receive(:new)
|
247
267
|
described_class.start(args)
|
248
268
|
end
|
249
269
|
|
250
270
|
it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do
|
251
271
|
ENV['PB_SERVER_TYPE'] = "Zmq"
|
252
|
-
runner.
|
272
|
+
expect(runner).to receive(:new)
|
253
273
|
described_class.start(args)
|
254
274
|
ENV.delete('PB_SERVER_TYPE')
|
255
275
|
end
|
256
|
-
|
257
|
-
it 'configures the connector type to be zmq' do
|
258
|
-
load "protobuf/zmq.rb"
|
259
|
-
::Protobuf.connector_type.should == :zmq
|
260
|
-
end
|
261
276
|
end
|
262
277
|
|
263
278
|
end
|