protobuf 2.8.13 → 3.0.0.rc1
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/CHANGES.md +84 -5
- data/CONTRIBUTING.md +3 -3
- data/Rakefile +46 -7
- data/lib/protobuf/cli.rb +2 -20
- data/lib/protobuf/decoder.rb +74 -0
- data/lib/protobuf/deprecator.rb +42 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +17 -16
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +86 -85
- data/lib/protobuf/encoder.rb +62 -0
- data/lib/protobuf/enum.rb +298 -37
- data/lib/protobuf/field/base_field.rb +41 -27
- data/lib/protobuf/field/bool_field.rb +22 -4
- data/lib/protobuf/field/bytes_field.rb +36 -15
- data/lib/protobuf/field/double_field.rb +10 -3
- data/lib/protobuf/field/enum_field.rb +21 -18
- data/lib/protobuf/field/field_array.rb +26 -16
- data/lib/protobuf/field/fixed32_field.rb +10 -4
- data/lib/protobuf/field/fixed64_field.rb +10 -3
- data/lib/protobuf/field/float_field.rb +18 -5
- data/lib/protobuf/field/int32_field.rb +14 -4
- data/lib/protobuf/field/int64_field.rb +14 -4
- data/lib/protobuf/field/integer_field.rb +9 -4
- data/lib/protobuf/field/message_field.rb +16 -7
- data/lib/protobuf/field/sfixed32_field.rb +10 -3
- data/lib/protobuf/field/sfixed64_field.rb +12 -7
- data/lib/protobuf/field/signed_integer_field.rb +7 -0
- data/lib/protobuf/field/sint32_field.rb +14 -4
- data/lib/protobuf/field/sint64_field.rb +14 -4
- data/lib/protobuf/field/string_field.rb +11 -1
- data/lib/protobuf/field/uint32_field.rb +14 -4
- data/lib/protobuf/field/uint64_field.rb +14 -4
- data/lib/protobuf/field/varint_field.rb +11 -9
- data/lib/protobuf/field.rb +42 -25
- data/lib/protobuf/generators/enum_generator.rb +12 -1
- data/lib/protobuf/generators/field_generator.rb +1 -1
- data/lib/protobuf/lifecycle.rb +3 -4
- data/lib/protobuf/message/fields.rb +122 -0
- data/lib/protobuf/message/serialization.rb +84 -0
- data/lib/protobuf/message.rb +21 -221
- data/lib/protobuf/optionable.rb +23 -0
- data/lib/protobuf/rpc/client.rb +2 -4
- data/lib/protobuf/rpc/connector.rb +0 -2
- data/lib/protobuf/rpc/connectors/common.rb +2 -2
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +14 -16
- data/lib/protobuf/rpc/env.rb +58 -0
- data/lib/protobuf/rpc/error.rb +8 -5
- data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
- data/lib/protobuf/rpc/middleware/logger.rb +91 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/middleware.rb +25 -0
- data/lib/protobuf/rpc/rpc.pb.rb +15 -16
- data/lib/protobuf/rpc/server.rb +14 -64
- data/lib/protobuf/rpc/servers/socket/server.rb +0 -2
- data/lib/protobuf/rpc/servers/socket/worker.rb +11 -15
- data/lib/protobuf/rpc/servers/zmq/util.rb +4 -1
- data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -13
- data/lib/protobuf/rpc/servers/zmq_runner.rb +1 -1
- data/lib/protobuf/rpc/service.rb +38 -72
- data/lib/protobuf/rpc/service_dispatcher.rb +20 -108
- data/lib/protobuf/version.rb +1 -2
- data/lib/protobuf.rb +5 -13
- data/protobuf.gemspec +5 -5
- data/spec/benchmark/tasks.rb +2 -77
- data/spec/functional/zmq_server_spec.rb +13 -21
- data/spec/lib/protobuf/cli_spec.rb +5 -43
- data/spec/lib/protobuf/enum_spec.rb +194 -61
- data/spec/lib/protobuf/field_spec.rb +194 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +24 -1
- data/spec/lib/protobuf/generators/field_generator_spec.rb +6 -6
- data/spec/lib/protobuf/message_spec.rb +52 -70
- data/spec/lib/protobuf/optionable_spec.rb +46 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +1 -93
- data/spec/lib/protobuf/rpc/connector_spec.rb +1 -7
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +8 -0
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +0 -6
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +10 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +30 -105
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_spec.rb +20 -24
- data/spec/lib/protobuf_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -4
- data/spec/support/packed_field.rb +15 -14
- data/spec/support/server.rb +4 -21
- data/spec/support/test/defaults.pb.rb +4 -4
- data/spec/support/test/enum.pb.rb +13 -1
- data/spec/support/test/enum.proto +15 -0
- data/spec/support/test/extended.pb.rb +1 -1
- data/spec/support/test/google_unittest.pb.rb +239 -241
- data/spec/support/test/google_unittest_import.pb.rb +2 -2
- data/spec/support/test/multi_field_extensions.pb.rb +2 -2
- data/spec/support/test/resource.pb.rb +19 -18
- data/spec/support/test/resource.proto +1 -0
- data/spec/support/test/resource_service.rb +5 -0
- metadata +78 -57
- data/bin/rprotoc +0 -8
- data/lib/protobuf/enum_value.rb +0 -85
- data/lib/protobuf/evented.rb +0 -37
- data/lib/protobuf/ext/eventmachine.rb +0 -14
- data/lib/protobuf/field/extension_fields.rb +0 -32
- data/lib/protobuf/message/decoder.rb +0 -72
- data/lib/protobuf/message/message.rb +0 -1
- data/lib/protobuf/rpc/connectors/em_client.rb +0 -84
- data/lib/protobuf/rpc/connectors/eventmachine.rb +0 -87
- data/lib/protobuf/rpc/servers/evented/server.rb +0 -36
- data/lib/protobuf/rpc/servers/evented_runner.rb +0 -31
- data/spec/functional/embedded_service_spec.rb +0 -7
- data/spec/functional/evented_server_spec.rb +0 -64
- data/spec/lib/protobuf/enum_value_spec.rb +0 -29
- data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +0 -19
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'protobuf/field'
|
3
|
+
|
4
|
+
describe ::Protobuf::Field do
|
5
|
+
|
6
|
+
describe '.build' do
|
7
|
+
pending
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.field_class' do
|
11
|
+
context 'when type is an enum class' do
|
12
|
+
it 'returns an enum field' do
|
13
|
+
expect(subject.field_class(::Test::EnumTestType)).to eq(::Protobuf::Field::EnumField)
|
14
|
+
expect(subject.field_type(::Test::EnumTestType)).to eq(::Test::EnumTestType)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when type is a message class' do
|
19
|
+
it 'returns a message field' do
|
20
|
+
expect(subject.field_class(::Test::Resource)).to eq(::Protobuf::Field::MessageField)
|
21
|
+
expect(subject.field_type(::Test::Resource)).to eq(::Test::Resource)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when type is a base field class' do
|
26
|
+
it 'returns that class' do
|
27
|
+
expect(subject.field_class(::Protobuf::Field::BoolField)).to eq(::Protobuf::Field::BoolField)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when type is a double field class or symbol' do
|
32
|
+
it 'returns that class' do
|
33
|
+
expected_field = ::Protobuf::Field::DoubleField
|
34
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
35
|
+
expect(subject.field_class(:double)).to eq(expected_field)
|
36
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
37
|
+
expect(subject.field_type(:double)).to eq(expected_field)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when type is a float field class or symbol' do
|
42
|
+
it 'returns that class' do
|
43
|
+
expected_field = ::Protobuf::Field::FloatField
|
44
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
45
|
+
expect(subject.field_class(:float)).to eq(expected_field)
|
46
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
47
|
+
expect(subject.field_type(:float)).to eq(expected_field)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when type is a int32 field class or symbol' do
|
52
|
+
it 'returns that class' do
|
53
|
+
expected_field = ::Protobuf::Field::Int32Field
|
54
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
55
|
+
expect(subject.field_class(:int32)).to eq(expected_field)
|
56
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
57
|
+
expect(subject.field_type(:int32)).to eq(expected_field)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when type is a int64 field class or symbol' do
|
62
|
+
it 'returns that class' do
|
63
|
+
expected_field = ::Protobuf::Field::Int64Field
|
64
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
65
|
+
expect(subject.field_class(:int64)).to eq(expected_field)
|
66
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
67
|
+
expect(subject.field_type(:int64)).to eq(expected_field)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when type is a uint32 field class or symbol' do
|
72
|
+
it 'returns that class' do
|
73
|
+
expected_field = ::Protobuf::Field::Uint32Field
|
74
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
75
|
+
expect(subject.field_class(:uint32)).to eq(expected_field)
|
76
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
77
|
+
expect(subject.field_type(:uint32)).to eq(expected_field)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when type is a uint64 field class or symbol' do
|
82
|
+
it 'returns that class' do
|
83
|
+
expected_field = ::Protobuf::Field::Uint64Field
|
84
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
85
|
+
expect(subject.field_class(:uint64)).to eq(expected_field)
|
86
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
87
|
+
expect(subject.field_type(:uint64)).to eq(expected_field)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when type is a sint32 field class or symbol' do
|
92
|
+
it 'returns that class' do
|
93
|
+
expected_field = ::Protobuf::Field::Sint32Field
|
94
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
95
|
+
expect(subject.field_class(:sint32)).to eq(expected_field)
|
96
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
97
|
+
expect(subject.field_type(:sint32)).to eq(expected_field)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when type is a sint64 field class or symbol' do
|
102
|
+
it 'returns that class' do
|
103
|
+
expected_field = ::Protobuf::Field::Sint64Field
|
104
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
105
|
+
expect(subject.field_class(:sint64)).to eq(expected_field)
|
106
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
107
|
+
expect(subject.field_type(:sint64)).to eq(expected_field)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when type is a fixed32 field class or symbol' do
|
112
|
+
it 'returns that class' do
|
113
|
+
expected_field = ::Protobuf::Field::Fixed32Field
|
114
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
115
|
+
expect(subject.field_class(:fixed32)).to eq(expected_field)
|
116
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
117
|
+
expect(subject.field_type(:fixed32)).to eq(expected_field)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when type is a fixed64 field class or symbol' do
|
122
|
+
it 'returns that class' do
|
123
|
+
expected_field = ::Protobuf::Field::Fixed64Field
|
124
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
125
|
+
expect(subject.field_class(:fixed64)).to eq(expected_field)
|
126
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
127
|
+
expect(subject.field_type(:fixed64)).to eq(expected_field)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when type is a sfixed32 field class or symbol' do
|
132
|
+
it 'returns that class' do
|
133
|
+
expected_field = ::Protobuf::Field::Sfixed32Field
|
134
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
135
|
+
expect(subject.field_class(:sfixed32)).to eq(expected_field)
|
136
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
137
|
+
expect(subject.field_type(:sfixed32)).to eq(expected_field)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when type is a sfixed64 field class or symbol' do
|
142
|
+
it 'returns that class' do
|
143
|
+
expected_field = ::Protobuf::Field::Sfixed64Field
|
144
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
145
|
+
expect(subject.field_class(:sfixed64)).to eq(expected_field)
|
146
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
147
|
+
expect(subject.field_type(:sfixed64)).to eq(expected_field)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
context 'when type is a string field class or symbol' do
|
153
|
+
it 'returns that class' do
|
154
|
+
expected_field = ::Protobuf::Field::StringField
|
155
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
156
|
+
expect(subject.field_class(:string)).to eq(expected_field)
|
157
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
158
|
+
expect(subject.field_type(:string)).to eq(expected_field)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
context 'when type is a bytes field class or symbol' do
|
164
|
+
it 'returns that class' do
|
165
|
+
expected_field = ::Protobuf::Field::BytesField
|
166
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
167
|
+
expect(subject.field_class(:bytes)).to eq(expected_field)
|
168
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
169
|
+
expect(subject.field_type(:bytes)).to eq(expected_field)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
context 'when type is a bool field class or symbol' do
|
175
|
+
it 'returns that class' do
|
176
|
+
expected_field = ::Protobuf::Field::BoolField
|
177
|
+
expect(subject.field_class(expected_field)).to eq(expected_field)
|
178
|
+
expect(subject.field_class(:bool)).to eq(expected_field)
|
179
|
+
expect(subject.field_type(expected_field)).to eq(expected_field)
|
180
|
+
expect(subject.field_type(:bool)).to eq(expected_field)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when type is not mapped' do
|
185
|
+
it 'raises an ArgumentError' do
|
186
|
+
expect {
|
187
|
+
subject.field_class("boom")
|
188
|
+
}.to raise_error
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
@@ -11,8 +11,10 @@ describe ::Protobuf::Generators::EnumGenerator do
|
|
11
11
|
{ :name => 'BAZ', :number => 3 }
|
12
12
|
]
|
13
13
|
}
|
14
|
+
let(:options) { nil }
|
14
15
|
let(:enum_fields) { { :name => 'TestEnum',
|
15
|
-
:value => values
|
16
|
+
:value => values,
|
17
|
+
:options => options } }
|
16
18
|
|
17
19
|
let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) }
|
18
20
|
|
@@ -33,6 +35,27 @@ end
|
|
33
35
|
subject.compile
|
34
36
|
subject.to_s.should eq(compiled)
|
35
37
|
end
|
38
|
+
|
39
|
+
context 'when allow_alias option is set' do
|
40
|
+
let(:compiled) {
|
41
|
+
%q{class TestEnum < ::Protobuf::Enum
|
42
|
+
set_option :allow_alias
|
43
|
+
|
44
|
+
define :FOO, 1
|
45
|
+
define :BAR, 2
|
46
|
+
define :BAZ, 3
|
47
|
+
end
|
48
|
+
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
let(:options) { { :allow_alias => true } }
|
53
|
+
|
54
|
+
it 'sets the allow_alias option' do
|
55
|
+
subject.compile
|
56
|
+
subject.to_s.should eq(compiled)
|
57
|
+
end
|
58
|
+
end
|
36
59
|
end
|
37
60
|
|
38
61
|
describe '#build_value' do
|
@@ -27,7 +27,7 @@ describe ::Protobuf::Generators::FieldGenerator do
|
|
27
27
|
describe '#compile' do
|
28
28
|
subject { described_class.new(field).to_s }
|
29
29
|
|
30
|
-
it { should eq "optional
|
30
|
+
it { should eq "optional :string, :foo_bar, 3\n" }
|
31
31
|
|
32
32
|
context 'when the type is another message' do
|
33
33
|
let(:type_enum) { :TYPE_MESSAGE }
|
@@ -39,7 +39,7 @@ describe ::Protobuf::Generators::FieldGenerator do
|
|
39
39
|
context 'when a default value is used' do
|
40
40
|
let(:type_enum) { :TYPE_INT32 }
|
41
41
|
let(:default_value) { '42' }
|
42
|
-
it { should eq "optional
|
42
|
+
it { should eq "optional :int32, :foo_bar, 3, :default => 42\n" }
|
43
43
|
|
44
44
|
context 'when type is an enum' do
|
45
45
|
let(:type_enum) { :TYPE_ENUM }
|
@@ -53,7 +53,7 @@ describe ::Protobuf::Generators::FieldGenerator do
|
|
53
53
|
let(:type_enum) { :TYPE_STRING }
|
54
54
|
let(:default_value) { "a default \"string\"" }
|
55
55
|
|
56
|
-
it { should eq %Q{optional
|
56
|
+
it { should eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} }
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'when float or double field type' do
|
@@ -79,19 +79,19 @@ describe ::Protobuf::Generators::FieldGenerator do
|
|
79
79
|
context 'when the field is an extension' do
|
80
80
|
let(:extendee) { 'foo.bar.Baz' }
|
81
81
|
|
82
|
-
it { should eq "optional
|
82
|
+
it { should eq "optional :string, :foo_bar, 3, :extension => true\n" }
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'when field is packed' do
|
86
86
|
let(:field_options) { { :packed => true } }
|
87
87
|
|
88
|
-
it { should eq "optional
|
88
|
+
it { should eq "optional :string, :foo_bar, 3, :packed => true\n" }
|
89
89
|
end
|
90
90
|
|
91
91
|
context 'when field is deprecated' do
|
92
92
|
let(:field_options) { { :deprecated => true } }
|
93
93
|
|
94
|
-
it { should eq "optional
|
94
|
+
it { should eq "optional :string, :foo_bar, 3, :deprecated => true\n" }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -10,13 +10,13 @@ describe Protobuf::Message do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe '
|
13
|
+
describe 'defining a new field' do
|
14
14
|
context 'when defining a field with a tag that has already been used' do
|
15
15
|
it 'raises a TagCollisionError' do
|
16
16
|
expect {
|
17
17
|
Class.new(Protobuf::Message) do
|
18
|
-
|
19
|
-
|
18
|
+
optional ::Protobuf::Field::Int32Field, :foo, 1
|
19
|
+
optional ::Protobuf::Field::Int32Field, :bar, 1
|
20
20
|
end
|
21
21
|
}.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/)
|
22
22
|
end
|
@@ -27,8 +27,8 @@ describe Protobuf::Message do
|
|
27
27
|
expect {
|
28
28
|
Class.new(Protobuf::Message) do
|
29
29
|
extensions 100...110
|
30
|
-
|
31
|
-
|
30
|
+
optional ::Protobuf::Field::Int32Field, :foo, 100
|
31
|
+
optional ::Protobuf::Field::Int32Field, :bar, 100, :extension => true
|
32
32
|
end
|
33
33
|
}.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/)
|
34
34
|
end
|
@@ -38,8 +38,8 @@ describe Protobuf::Message do
|
|
38
38
|
it 'raises a DuplicateFieldNameError' do
|
39
39
|
expect {
|
40
40
|
Class.new(Protobuf::Message) do
|
41
|
-
|
42
|
-
|
41
|
+
optional ::Protobuf::Field::Int32Field, :foo, 1
|
42
|
+
optional ::Protobuf::Field::Int32Field, :foo, 2
|
43
43
|
end
|
44
44
|
}.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/)
|
45
45
|
end
|
@@ -50,8 +50,8 @@ describe Protobuf::Message do
|
|
50
50
|
expect {
|
51
51
|
Class.new(Protobuf::Message) do
|
52
52
|
extensions 100...110
|
53
|
-
|
54
|
-
|
53
|
+
optional ::Protobuf::Field::Int32Field, :foo, 1
|
54
|
+
optional ::Protobuf::Field::Int32Field, :foo, 100, :extension => true
|
55
55
|
end
|
56
56
|
}.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/)
|
57
57
|
end
|
@@ -289,44 +289,9 @@ describe Protobuf::Message do
|
|
289
289
|
its(:to_json) { should eq '{"name":"Test Name","active":false}' }
|
290
290
|
end
|
291
291
|
|
292
|
-
describe '.to_json' do
|
293
|
-
it 'returns the class name of the message for use in json encoding' do
|
294
|
-
expect {
|
295
|
-
::Timeout.timeout(0.1) do
|
296
|
-
expect(::Test::Resource.to_json).to eq("Test::Resource")
|
297
|
-
end
|
298
|
-
}.not_to raise_error
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
describe '#get_field_by_name' do
|
303
|
-
subject do
|
304
|
-
::Test::Resource.new({ :name => 'Test Name', :date_created => Time.now.to_i })
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'when name is a valid field' do
|
308
|
-
let(:valid_field) { subject.get_field_by_name(:name) }
|
309
|
-
specify { valid_field.should be_a ::Protobuf::Field::StringField }
|
310
|
-
specify { valid_field.name.should eq :name }
|
311
|
-
end
|
312
|
-
|
313
|
-
context 'when name is not a valid field' do
|
314
|
-
specify do
|
315
|
-
subject.get_field_by_name(1).should be_nil
|
316
|
-
end
|
317
|
-
|
318
|
-
specify do
|
319
|
-
subject.get_field_by_name(:nothere).should be_nil
|
320
|
-
end
|
321
|
-
|
322
|
-
specify do
|
323
|
-
subject.get_field_by_name(nil).should be_nil
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
292
|
describe "#define_setter" do
|
329
293
|
subject { ::Test::Resource.new }
|
294
|
+
|
330
295
|
it "allows string fields to be set to nil" do
|
331
296
|
expect { subject.name = nil }.to_not raise_error
|
332
297
|
end
|
@@ -336,40 +301,57 @@ describe Protobuf::Message do
|
|
336
301
|
end
|
337
302
|
end
|
338
303
|
|
339
|
-
describe '
|
340
|
-
|
304
|
+
describe '.get_extension_field' do
|
305
|
+
it 'fetches an extension field by its tag' do
|
306
|
+
field = ::Test::Resource.get_extension_field(100)
|
307
|
+
expect(field).to be_a(::Protobuf::Field::BoolField)
|
308
|
+
expect(field.tag).to eq(100)
|
309
|
+
expect(field.name).to eq(:ext_is_searchable)
|
310
|
+
expect(field).to be_extension
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'fetches an extension field by its symbolized name' do
|
314
|
+
expect(::Test::Resource.get_extension_field(:ext_is_searchable)).to be_a(::Protobuf::Field::BoolField)
|
315
|
+
expect(::Test::Resource.get_extension_field('ext_is_searchable')).to be_a(::Protobuf::Field::BoolField)
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'returns nil when attempting to get a non-extension field' do
|
319
|
+
expect(::Test::Resource.get_extension_field(1)).to be_nil
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'returns nil when field is not found' do
|
323
|
+
::Test::Resource.get_extension_field(-1).should be_nil
|
324
|
+
::Test::Resource.get_extension_field(nil).should be_nil
|
325
|
+
end
|
341
326
|
end
|
342
327
|
|
343
|
-
describe '
|
344
|
-
|
345
|
-
::Test::Resource.
|
328
|
+
describe '.get_field' do
|
329
|
+
it 'fetches a non-extension field by its tag' do
|
330
|
+
field = ::Test::Resource.get_field(1)
|
331
|
+
expect(field).to be_a(::Protobuf::Field::StringField)
|
332
|
+
expect(field.tag).to eq(1)
|
333
|
+
expect(field.name).to eq(:name)
|
334
|
+
expect(field).not_to be_extension
|
346
335
|
end
|
347
336
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
specify { valid_field.name.should eq :name }
|
337
|
+
it 'fetches a non-extension field by its symbolized name' do
|
338
|
+
expect(::Test::Resource.get_field(:name)).to be_a(::Protobuf::Field::StringField)
|
339
|
+
expect(::Test::Resource.get_field('name')).to be_a(::Protobuf::Field::StringField)
|
352
340
|
end
|
353
341
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
end
|
342
|
+
it 'fetches an extension field when forced' do
|
343
|
+
expect(::Test::Resource.get_field(100, true)).to be_a(::Protobuf::Field::BoolField)
|
344
|
+
expect(::Test::Resource.get_field(:ext_is_searchable, true)).to be_a(::Protobuf::Field::BoolField)
|
345
|
+
expect(::Test::Resource.get_field('ext_is_searchable', true)).to be_a(::Protobuf::Field::BoolField)
|
359
346
|
end
|
360
347
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
subject.get_field_by_tag("not a number")
|
365
|
-
}.to raise_error(::Protobuf::FieldNotDefinedError, /.*not a number.*#{subject.class.name}/)
|
366
|
-
end
|
348
|
+
it 'returns nil when attempting to get an extension field' do
|
349
|
+
expect(::Test::Resource.get_field(100)).to be_nil
|
350
|
+
end
|
367
351
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
}.to raise_error(::Protobuf::FieldNotDefinedError, /.*nil.*#{subject.class.name}/)
|
372
|
-
end
|
352
|
+
it 'returns nil when field is not defined' do
|
353
|
+
::Test::Resource.get_field(-1).should be_nil
|
354
|
+
::Test::Resource.get_field(nil).should be_nil
|
373
355
|
end
|
374
356
|
end
|
375
357
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'protobuf/optionable'
|
3
|
+
|
4
|
+
describe 'Optionable' do
|
5
|
+
|
6
|
+
describe '.set_option' do
|
7
|
+
before(:all) do
|
8
|
+
OptionableSetOptionTest = ::Class.new do
|
9
|
+
include ::Protobuf::Optionable
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'stores the given option and value' do
|
14
|
+
expect(OptionableSetOptionTest).to respond_to(:set_option)
|
15
|
+
expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2)
|
16
|
+
expect {
|
17
|
+
OptionableSetOptionTest.set_option(:foo, :bar)
|
18
|
+
}.to_not raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'defaults the value to true' do
|
22
|
+
OptionableSetOptionTest.set_option(:baz_enabled)
|
23
|
+
expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.get_option' do
|
28
|
+
before(:all) do
|
29
|
+
OptionableGetOptionTest = ::Class.new do
|
30
|
+
include ::Protobuf::Optionable
|
31
|
+
set_option :foo, :bar
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'retrieves the option for the given name, if any' do
|
36
|
+
expect(OptionableGetOptionTest.get_option(:foo)).to eq(:bar)
|
37
|
+
expect(OptionableGetOptionTest.get_option(:baz)).to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'retrieves the option in the context of an instance' do
|
41
|
+
expect(OptionableGetOptionTest.new.get_option(:foo)).to eq(:bar)
|
42
|
+
expect(OptionableGetOptionTest.new.get_option(:baz)).to be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -3,99 +3,7 @@ require 'spec/support/test/resource_service'
|
|
3
3
|
|
4
4
|
describe Protobuf::Rpc::Client do
|
5
5
|
before(:each) do
|
6
|
-
load 'protobuf/
|
7
|
-
end
|
8
|
-
|
9
|
-
context "when using fiber based calls", :skip => true do
|
10
|
-
it "waits for response" do
|
11
|
-
EventMachine.fiber_run do
|
12
|
-
StubServer.new(:delay => 1) do |server|
|
13
|
-
client = Test::ResourceService.client
|
14
|
-
start = now
|
15
|
-
|
16
|
-
client.find(:name => "Test Name", :active => true) do |c|
|
17
|
-
c.on_success do |succ|
|
18
|
-
succ.name.should eq("Test Name")
|
19
|
-
succ.status.should eq(Test::StatusType::ENABLED)
|
20
|
-
end
|
21
|
-
|
22
|
-
c.on_failure do |err|
|
23
|
-
raise err.inspect
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
(now - start).should be_within(server.options.delay * 0.10).of(server.options.delay)
|
28
|
-
end
|
29
|
-
|
30
|
-
EM.stop
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it "throws and error when call is attempted without 'EventMachine.fiber_run'" do
|
35
|
-
subject = Proc.new do
|
36
|
-
EventMachine.run do
|
37
|
-
StubServer.new(:delay => 1) do |server|
|
38
|
-
client = Test::ResourceService.client
|
39
|
-
client.find(:name => "Test Name", :active => true)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
subject.should raise_error(RuntimeError, /EM.fiber_run/)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "throws a timeout when client timeout is exceeded" do
|
48
|
-
error = nil
|
49
|
-
test_proc = Proc.new do
|
50
|
-
EventMachine.fiber_run do
|
51
|
-
StubServer.new(:delay => 2) do |server|
|
52
|
-
client = Test::ResourceService.client(:timeout => 1)
|
53
|
-
client.find(:name => "Test Name", :active => true) do |cl|
|
54
|
-
cl.on_success {}
|
55
|
-
cl.on_failure {|f| error = f}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
EM.stop
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test_proc.call
|
63
|
-
error.message.should =~ /timeout/i
|
64
|
-
end
|
65
|
-
|
66
|
-
context "without reactor_running?" do
|
67
|
-
|
68
|
-
it "throws a timeout when client timeout is exceeded" do
|
69
|
-
subject = Proc.new do
|
70
|
-
StubServer.new(:delay => 2) do |server|
|
71
|
-
client = Test::ResourceService.client(:timeout => 1)
|
72
|
-
client.find(:name => "Test Name", :active => true)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
subject.should raise_error(RuntimeError, /timeout/i)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "calls failure_cb & throws a timeout when client timeout is exceeded" do
|
80
|
-
failure_message = nil
|
81
|
-
|
82
|
-
subject = Proc.new do
|
83
|
-
StubServer.new(:delay => 2) do |server|
|
84
|
-
client = Test::ResourceService.client(:timeout => 1)
|
85
|
-
client.find(:name => "Test Name", :active => true) do |c|
|
86
|
-
c.on_failure do |f|
|
87
|
-
failure_message = f.message
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
subject.call
|
94
|
-
failure_message.should match(/timeout/)
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
6
|
+
load 'protobuf/socket.rb'
|
99
7
|
end
|
100
8
|
|
101
9
|
context 'when creating a client from a service' do
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'protobuf/socket'
|
3
|
-
require 'protobuf/evented'
|
4
3
|
require 'protobuf/zmq'
|
5
4
|
|
6
5
|
describe ::Protobuf::Rpc::Connector do
|
@@ -14,15 +13,10 @@ describe ::Protobuf::Rpc::Connector do
|
|
14
13
|
end
|
15
14
|
|
16
15
|
context 'Protobuf.connector_type is not a known value' do
|
17
|
-
before { ::Protobuf.connector_type
|
16
|
+
before { ::Protobuf.stub(:connector_type) { :foo } }
|
18
17
|
it { should eq ::Protobuf::Rpc::Connectors::Socket }
|
19
18
|
end
|
20
19
|
|
21
|
-
context 'Protobuf.connector_type is evented' do
|
22
|
-
before { ::Protobuf.connector_type = :evented }
|
23
|
-
it { should eq ::Protobuf::Rpc::Connectors::EventMachine }
|
24
|
-
end
|
25
|
-
|
26
20
|
context 'Protobuf.connector_type is zmq' do
|
27
21
|
before { ::Protobuf.connector_type = :zmq }
|
28
22
|
it { should eq ::Protobuf::Rpc::Connectors::Zmq }
|
@@ -28,6 +28,14 @@ describe ::Protobuf::Rpc::Connectors::Zmq do
|
|
28
28
|
::ZMQ::Context.stub(:new).and_return(zmq_context_double)
|
29
29
|
end
|
30
30
|
|
31
|
+
before(:all) do
|
32
|
+
@ping_port_before = ENV['PB_RPC_PING_PORT']
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:all) do
|
36
|
+
ENV['PB_RPC_PING_PORT'] = @ping_port_before
|
37
|
+
end
|
38
|
+
|
31
39
|
describe "#lookup_server_uri" do
|
32
40
|
let(:service_directory) { double('ServiceDirectory', :running? => running? ) }
|
33
41
|
let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) }
|