protobuffy 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +12 -0
  4. data/.yardopts +5 -0
  5. data/CHANGES.md +261 -0
  6. data/CONTRIBUTING.md +16 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +14 -0
  9. data/README.md +58 -0
  10. data/Rakefile +61 -0
  11. data/bin/protoc-gen-ruby +17 -0
  12. data/bin/rpc_server +4 -0
  13. data/examples/bin/reverse-client-http +4 -0
  14. data/examples/bin/reverse-client-socket +4 -0
  15. data/examples/bin/reverse-client-zmq +4 -0
  16. data/examples/config.ru +6 -0
  17. data/examples/definitions/example/reverse.proto +12 -0
  18. data/examples/lib/example/reverse-client.rb +23 -0
  19. data/examples/lib/example/reverse-service.rb +9 -0
  20. data/examples/lib/example/reverse.pb.rb +36 -0
  21. data/lib/protobuf.rb +106 -0
  22. data/lib/protobuf/cli.rb +249 -0
  23. data/lib/protobuf/code_generator.rb +41 -0
  24. data/lib/protobuf/decoder.rb +74 -0
  25. data/lib/protobuf/deprecator.rb +42 -0
  26. data/lib/protobuf/descriptors.rb +3 -0
  27. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +52 -0
  28. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +249 -0
  29. data/lib/protobuf/encoder.rb +62 -0
  30. data/lib/protobuf/enum.rb +319 -0
  31. data/lib/protobuf/exceptions.rb +9 -0
  32. data/lib/protobuf/field.rb +74 -0
  33. data/lib/protobuf/field/base_field.rb +280 -0
  34. data/lib/protobuf/field/bool_field.rb +53 -0
  35. data/lib/protobuf/field/bytes_field.rb +81 -0
  36. data/lib/protobuf/field/double_field.rb +26 -0
  37. data/lib/protobuf/field/enum_field.rb +57 -0
  38. data/lib/protobuf/field/field_array.rb +86 -0
  39. data/lib/protobuf/field/fixed32_field.rb +25 -0
  40. data/lib/protobuf/field/fixed64_field.rb +29 -0
  41. data/lib/protobuf/field/float_field.rb +38 -0
  42. data/lib/protobuf/field/int32_field.rb +22 -0
  43. data/lib/protobuf/field/int64_field.rb +22 -0
  44. data/lib/protobuf/field/integer_field.rb +24 -0
  45. data/lib/protobuf/field/message_field.rb +66 -0
  46. data/lib/protobuf/field/sfixed32_field.rb +28 -0
  47. data/lib/protobuf/field/sfixed64_field.rb +29 -0
  48. data/lib/protobuf/field/signed_integer_field.rb +30 -0
  49. data/lib/protobuf/field/sint32_field.rb +22 -0
  50. data/lib/protobuf/field/sint64_field.rb +22 -0
  51. data/lib/protobuf/field/string_field.rb +35 -0
  52. data/lib/protobuf/field/uint32_field.rb +22 -0
  53. data/lib/protobuf/field/uint64_field.rb +22 -0
  54. data/lib/protobuf/field/varint_field.rb +68 -0
  55. data/lib/protobuf/generators/base.rb +71 -0
  56. data/lib/protobuf/generators/enum_generator.rb +42 -0
  57. data/lib/protobuf/generators/extension_generator.rb +28 -0
  58. data/lib/protobuf/generators/field_generator.rb +132 -0
  59. data/lib/protobuf/generators/file_generator.rb +140 -0
  60. data/lib/protobuf/generators/group_generator.rb +113 -0
  61. data/lib/protobuf/generators/message_generator.rb +99 -0
  62. data/lib/protobuf/generators/printable.rb +161 -0
  63. data/lib/protobuf/generators/service_generator.rb +27 -0
  64. data/lib/protobuf/http.rb +20 -0
  65. data/lib/protobuf/lifecycle.rb +46 -0
  66. data/lib/protobuf/logger.rb +86 -0
  67. data/lib/protobuf/message.rb +182 -0
  68. data/lib/protobuf/message/fields.rb +122 -0
  69. data/lib/protobuf/message/serialization.rb +84 -0
  70. data/lib/protobuf/optionable.rb +23 -0
  71. data/lib/protobuf/rpc/buffer.rb +79 -0
  72. data/lib/protobuf/rpc/client.rb +168 -0
  73. data/lib/protobuf/rpc/connector.rb +21 -0
  74. data/lib/protobuf/rpc/connectors/base.rb +54 -0
  75. data/lib/protobuf/rpc/connectors/common.rb +172 -0
  76. data/lib/protobuf/rpc/connectors/http.rb +90 -0
  77. data/lib/protobuf/rpc/connectors/socket.rb +73 -0
  78. data/lib/protobuf/rpc/connectors/zmq.rb +205 -0
  79. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +47 -0
  80. data/lib/protobuf/rpc/env.rb +58 -0
  81. data/lib/protobuf/rpc/error.rb +28 -0
  82. data/lib/protobuf/rpc/error/client_error.rb +31 -0
  83. data/lib/protobuf/rpc/error/server_error.rb +43 -0
  84. data/lib/protobuf/rpc/middleware.rb +25 -0
  85. data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
  86. data/lib/protobuf/rpc/middleware/logger.rb +91 -0
  87. data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
  88. data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
  89. data/lib/protobuf/rpc/middleware/runner.rb +18 -0
  90. data/lib/protobuf/rpc/rpc.pb.rb +53 -0
  91. data/lib/protobuf/rpc/server.rb +39 -0
  92. data/lib/protobuf/rpc/servers/http/server.rb +101 -0
  93. data/lib/protobuf/rpc/servers/http_runner.rb +34 -0
  94. data/lib/protobuf/rpc/servers/socket/server.rb +113 -0
  95. data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
  96. data/lib/protobuf/rpc/servers/socket_runner.rb +34 -0
  97. data/lib/protobuf/rpc/servers/zmq/broker.rb +155 -0
  98. data/lib/protobuf/rpc/servers/zmq/server.rb +313 -0
  99. data/lib/protobuf/rpc/servers/zmq/util.rb +47 -0
  100. data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
  101. data/lib/protobuf/rpc/servers/zmq_runner.rb +51 -0
  102. data/lib/protobuf/rpc/service.rb +179 -0
  103. data/lib/protobuf/rpc/service_directory.rb +245 -0
  104. data/lib/protobuf/rpc/service_dispatcher.rb +46 -0
  105. data/lib/protobuf/rpc/service_filters.rb +273 -0
  106. data/lib/protobuf/rpc/stat.rb +148 -0
  107. data/lib/protobuf/socket.rb +22 -0
  108. data/lib/protobuf/tasks.rb +1 -0
  109. data/lib/protobuf/tasks/compile.rake +61 -0
  110. data/lib/protobuf/version.rb +3 -0
  111. data/lib/protobuf/wire_type.rb +10 -0
  112. data/lib/protobuf/zmq.rb +21 -0
  113. data/proto/dynamic_discovery.proto +44 -0
  114. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  115. data/proto/google/protobuf/descriptor.proto +620 -0
  116. data/proto/rpc.proto +62 -0
  117. data/protobuffy.gemspec +37 -0
  118. data/spec/benchmark/tasks.rb +113 -0
  119. data/spec/bin/protoc-gen-ruby_spec.rb +18 -0
  120. data/spec/data/data.bin +3 -0
  121. data/spec/data/types.bin +0 -0
  122. data/spec/encoding/all_types_spec.rb +91 -0
  123. data/spec/encoding/extreme_values_spec.rb +0 -0
  124. data/spec/functional/socket_server_spec.rb +59 -0
  125. data/spec/functional/zmq_server_spec.rb +103 -0
  126. data/spec/lib/protobuf/cli_spec.rb +267 -0
  127. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  128. data/spec/lib/protobuf/enum_spec.rb +239 -0
  129. data/spec/lib/protobuf/field/int32_field_spec.rb +7 -0
  130. data/spec/lib/protobuf/field/string_field_spec.rb +46 -0
  131. data/spec/lib/protobuf/field_spec.rb +194 -0
  132. data/spec/lib/protobuf/generators/base_spec.rb +87 -0
  133. data/spec/lib/protobuf/generators/enum_generator_spec.rb +68 -0
  134. data/spec/lib/protobuf/generators/extension_generator_spec.rb +43 -0
  135. data/spec/lib/protobuf/generators/field_generator_spec.rb +99 -0
  136. data/spec/lib/protobuf/generators/file_generator_spec.rb +29 -0
  137. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  138. data/spec/lib/protobuf/generators/service_generator_spec.rb +43 -0
  139. data/spec/lib/protobuf/lifecycle_spec.rb +89 -0
  140. data/spec/lib/protobuf/logger_spec.rb +136 -0
  141. data/spec/lib/protobuf/message_spec.rb +368 -0
  142. data/spec/lib/protobuf/optionable_spec.rb +46 -0
  143. data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
  144. data/spec/lib/protobuf/rpc/connector_spec.rb +26 -0
  145. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
  146. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +170 -0
  147. data/spec/lib/protobuf/rpc/connectors/connector_spec.rb +13 -0
  148. data/spec/lib/protobuf/rpc/connectors/http_spec.rb +61 -0
  149. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +24 -0
  150. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +129 -0
  151. data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
  152. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
  153. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
  154. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
  155. data/spec/lib/protobuf/rpc/servers/http/server_spec.rb +104 -0
  156. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
  157. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +41 -0
  158. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
  159. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
  160. data/spec/lib/protobuf/rpc/service_directory_spec.rb +295 -0
  161. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +52 -0
  162. data/spec/lib/protobuf/rpc/service_filters_spec.rb +484 -0
  163. data/spec/lib/protobuf/rpc/service_spec.rb +161 -0
  164. data/spec/lib/protobuf/rpc/stat_spec.rb +151 -0
  165. data/spec/lib/protobuf_spec.rb +78 -0
  166. data/spec/spec_helper.rb +57 -0
  167. data/spec/support/all.rb +7 -0
  168. data/spec/support/packed_field.rb +22 -0
  169. data/spec/support/server.rb +94 -0
  170. data/spec/support/test/all_types.data.bin +0 -0
  171. data/spec/support/test/all_types.data.txt +119 -0
  172. data/spec/support/test/defaults.pb.rb +25 -0
  173. data/spec/support/test/defaults.proto +9 -0
  174. data/spec/support/test/enum.pb.rb +59 -0
  175. data/spec/support/test/enum.proto +34 -0
  176. data/spec/support/test/extended.pb.rb +22 -0
  177. data/spec/support/test/extended.proto +10 -0
  178. data/spec/support/test/extreme_values.data.bin +0 -0
  179. data/spec/support/test/google_unittest.pb.rb +543 -0
  180. data/spec/support/test/google_unittest.proto +713 -0
  181. data/spec/support/test/google_unittest_import.pb.rb +37 -0
  182. data/spec/support/test/google_unittest_import.proto +64 -0
  183. data/spec/support/test/google_unittest_import_public.pb.rb +8 -0
  184. data/spec/support/test/google_unittest_import_public.proto +38 -0
  185. data/spec/support/test/multi_field_extensions.pb.rb +56 -0
  186. data/spec/support/test/multi_field_extensions.proto +33 -0
  187. data/spec/support/test/resource.pb.rb +117 -0
  188. data/spec/support/test/resource.proto +94 -0
  189. data/spec/support/test/resource_service.rb +26 -0
  190. data/spec/support/test_app_file.rb +2 -0
  191. data/spec/support/tolerance_matcher.rb +40 -0
  192. metadata +367 -0
@@ -0,0 +1,161 @@
1
+ require 'spec_helper'
2
+ require 'spec/support/test/resource_service'
3
+
4
+ describe Protobuf::Rpc::Service do
5
+
6
+ context 'class methods' do
7
+ subject { Test::ResourceService }
8
+
9
+ before :each do
10
+ reset_service_location Test::ResourceService
11
+ end
12
+
13
+ describe '.host' do
14
+ its(:host) { should eq described_class::DEFAULT_HOST }
15
+ end
16
+
17
+ describe '.host=' do
18
+ before { subject.host = 'mynewhost.com' }
19
+ its(:host) { should eq 'mynewhost.com' }
20
+ end
21
+
22
+ describe '.port' do
23
+ its(:port) { should eq described_class::DEFAULT_PORT }
24
+ end
25
+
26
+ describe '.port=' do
27
+ before { subject.port = 12345 }
28
+ its(:port) { should eq 12345 }
29
+ end
30
+
31
+ describe '.configure' do
32
+ context 'when providing a host' do
33
+ before { subject.configure(:host => 'mynewhost.com') }
34
+ its(:host) { should eq 'mynewhost.com' }
35
+ end
36
+
37
+ context 'when providing a port' do
38
+ before { subject.configure(:port => 12345) }
39
+ its(:port) { should eq 12345 }
40
+ end
41
+ end
42
+
43
+ describe '.located_at' do
44
+ context 'when given location is empty' do
45
+ before { subject.located_at(nil) }
46
+ its(:host) { should eq described_class::DEFAULT_HOST }
47
+ its(:port) { should eq described_class::DEFAULT_PORT }
48
+ end
49
+
50
+ context 'when given location is invalid' do
51
+ before { subject.located_at('i like pie') }
52
+ its(:host) { should eq described_class::DEFAULT_HOST }
53
+ its(:port) { should eq described_class::DEFAULT_PORT }
54
+ end
55
+
56
+ context 'when given location contains a host and port' do
57
+ before { subject.located_at('mynewdomain.com:12345') }
58
+ its(:host) { should eq 'mynewdomain.com' }
59
+ its(:port) { should eq 12345 }
60
+ end
61
+ end
62
+
63
+ describe '.client' do
64
+ it 'initializes a client object for this service' do
65
+ client = double('client')
66
+ ::Protobuf::Rpc::Client.should_receive(:new)
67
+ .with(hash_including({ :service => subject,
68
+ :host => subject.host,
69
+ :port => subject.port }))
70
+ .and_return(client)
71
+ subject.client.should eq client
72
+ end
73
+ end
74
+
75
+ describe '.rpc' do
76
+ before { Test::ResourceService.rpc(:update, Test::ResourceFindRequest, Test::Resource) }
77
+ subject { Test::ResourceService.rpcs[:update] }
78
+ its(:method) { should eq :update }
79
+ its(:request_type) { should eq Test::ResourceFindRequest }
80
+ its(:response_type) { should eq Test::Resource }
81
+ end
82
+
83
+ describe '.rpc_method?' do
84
+ before { Test::ResourceService.rpc(:delete, Test::Resource, Test::Resource) }
85
+
86
+ context 'when given name is a pre-defined rpc method' do
87
+ it 'returns true' do
88
+ subject.rpc_method?(:delete).should be_true
89
+ end
90
+ end
91
+
92
+ context 'when given name is not a pre-defined rpc method' do
93
+ it 'returns false' do
94
+ subject.rpc_method?(:zoobaboo).should be_false
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ context 'instance methods' do
101
+ context 'when invoking a service call' do
102
+ before(:all) do
103
+ class ::NewTestService < Protobuf::Rpc::Service
104
+ rpc :find_with_implied_response, Test::ResourceFindRequest, Test::Resource
105
+ def find_with_implied_response
106
+ response.name = 'Implicit response'
107
+ end
108
+
109
+ rpc :find_with_respond_with, Test::ResourceFindRequest, Test::Resource
110
+ def find_with_respond_with
111
+ custom = Test::Resource.new(:name => 'Custom response')
112
+ respond_with(custom)
113
+ end
114
+
115
+ rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource
116
+ def find_with_rpc_failed
117
+ rpc_failed('This is a failed endpoint')
118
+ response.name = 'Name will still be set'
119
+ end
120
+ end
121
+ end
122
+
123
+ let(:request) { Test::ResourceFindRequest.new(:name => 'resource') }
124
+ let(:response) { Test::Resource.new }
125
+
126
+ context 'when calling the rpc method' do
127
+ context 'when response is implied' do
128
+ let(:env) {
129
+ Protobuf::Rpc::Env.new(
130
+ 'request' => request,
131
+ 'response_type' => response_type
132
+ )
133
+ }
134
+ let(:response_type) { service.rpcs[:find_with_implied_response].response_type }
135
+ let(:service) { NewTestService }
136
+
137
+ subject { NewTestService.new(env) }
138
+
139
+ before { subject.find_with_implied_response }
140
+ its(:response) { should be_a(Test::Resource) }
141
+ specify { subject.response.name.should eq 'Implicit response' }
142
+ end
143
+
144
+ context 'when using respond_with paradigm' do
145
+ let(:env) {
146
+ Protobuf::Rpc::Env.new(
147
+ 'method_name' => :find_with_respond_with,
148
+ 'request' => request
149
+ )
150
+ }
151
+
152
+ subject { NewTestService.new(env) }
153
+
154
+ before { subject.find_with_respond_with }
155
+ its(:response) { should be_a(Test::Resource) }
156
+ specify { subject.response.name.should eq 'Custom response' }
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+ require 'timecop'
3
+ require 'active_support/core_ext/numeric/time'
4
+
5
+ describe ::Protobuf::Rpc::Stat do
6
+
7
+ before(:all) do
8
+ unless defined?(BarService)
9
+ class BarService < ::Struct.new(:method_name); end
10
+ end
11
+ end
12
+
13
+ describe 'server mode' do
14
+ it 'describes a server response to a client' do
15
+ ::Timecop.freeze(10.minutes.ago) do
16
+ stats = ::Protobuf::Rpc::Stat.new(:SERVER)
17
+ stats.client = 'myserver1'
18
+ stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars))
19
+ stats.request_size = 43
20
+ stats.response_size = 1302
21
+
22
+ ::Timecop.freeze(1.62.seconds.from_now) do
23
+ stats.stop
24
+ stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}"
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'when request is still running' do
30
+ it 'omits response size, duration, and timestamp' do
31
+ stats = ::Protobuf::Rpc::Stat.new(:SERVER)
32
+ stats.client = 'myserver1'
33
+ stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars))
34
+ stats.request_size = 43
35
+ stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-"
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'client mode' do
41
+ it 'describes a client request to a server' do
42
+ ::Timecop.freeze(10.minutes.ago) do
43
+ stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
44
+ stats.server = ['30000', 'myserver1.myhost.com']
45
+ stats.service = 'Foo::BarService'
46
+ stats.method_name = 'find_bars'
47
+ stats.request_size = 37
48
+ stats.response_size = 12345
49
+
50
+ ::Timecop.freeze(0.832.seconds.from_now) do
51
+ stats.stop
52
+ stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}"
53
+ end
54
+
55
+ end
56
+ end
57
+
58
+ context 'when request is still running' do
59
+ it 'omits response size, duration, and timestamp' do
60
+ stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
61
+ stats.server = ['30000', 'myserver1.myhost.com']
62
+ stats.service = 'Foo::BarService'
63
+ stats.method_name = 'find_bars'
64
+ stats.request_size = 37
65
+ stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-"
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "statsd_base_path" do
71
+ let(:stats) { described_class.new(:CLIENT) }
72
+ subject(:statsd_base_path) { stats.statsd_base_path }
73
+
74
+ before :each do
75
+ stats.service = 'Foo::BarService'
76
+ stats.method_name = 'find_bars'
77
+ end
78
+
79
+ it "should use correct base path" do
80
+ expect(statsd_base_path).to eq "rpc.foo.barservice.find_bars"
81
+ end
82
+ end
83
+
84
+ describe "#stop" do
85
+ let(:stats) { described_class.new(:CLIENT) }
86
+ let(:start_time) { Time.now - 3000 }
87
+ let(:end_time) { Time.now }
88
+ let(:service) { 'Foo::BarService' }
89
+ let(:method_name) { 'find_bars' }
90
+ let(:stats_path) { 'rpc.foo.barservice.find_bars' }
91
+
92
+ before :each do
93
+ stats.service = service
94
+ stats.method_name = method_name
95
+ stats.start_time = start_time
96
+ stats.end_time = end_time
97
+ stats.stub(:statsd_base_path).and_return(stats_path)
98
+ end
99
+
100
+ subject(:stop) { stats.stop }
101
+
102
+ context "when statsd_client hasn't been set" do
103
+ it "should not raise" do
104
+ expect{ stop }.not_to raise_error
105
+ end
106
+ end
107
+
108
+ context "when statsd_client has been set" do
109
+ let(:statsd_client) { double("Statsd::Client") }
110
+
111
+ before :each do
112
+ Protobuf::Rpc::Stat.statsd_client = statsd_client
113
+ end
114
+
115
+ after :each do
116
+ Protobuf::Rpc::Stat.statsd_client = nil
117
+ end
118
+
119
+ context "on success" do
120
+ before :each do
121
+ stats.success
122
+ end
123
+
124
+ it "should increment the proper stats" do
125
+ expect(statsd_client).to receive(:increment).with("#{stats_path}.success")
126
+ expect(statsd_client).to receive(:timing).with("#{stats_path}.time",
127
+ end_time - start_time)
128
+
129
+ stop
130
+ end
131
+ end
132
+
133
+ context "on failure" do
134
+ let(:code) { 8 }
135
+
136
+ before :each do
137
+ stats.failure(code)
138
+ end
139
+
140
+ it "should increment the proper stats" do
141
+ expect(statsd_client).to receive(:increment).with("#{stats_path}.failure.total")
142
+ expect(statsd_client).to receive(:increment).with("#{stats_path}.failure.#{code}")
143
+ expect(statsd_client).to receive(:timing).with("#{stats_path}.time",
144
+ end_time - start_time)
145
+
146
+ stop
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+ require 'protobuf'
3
+
4
+ describe ::Protobuf do
5
+
6
+ describe '.client_host' do
7
+ after { ::Protobuf.instance_variable_set(:@_client_host, nil) }
8
+
9
+ subject { ::Protobuf.client_host }
10
+
11
+ context 'when client_host is not pre-configured' do
12
+ it { should eq `hostname`.chomp }
13
+ end
14
+
15
+ context 'when client_host is pre-configured' do
16
+ let(:hostname) { 'override.myhost.com' }
17
+ before { ::Protobuf.client_host = hostname }
18
+ it { should eq hostname }
19
+ end
20
+ end
21
+
22
+ describe '.connector_type' do
23
+ before { described_class.instance_variable_set(:@_connector_type, nil) }
24
+
25
+ it 'defaults to socket' do
26
+ described_class.connector_type.should eq :socket
27
+ end
28
+
29
+ it 'accepts socket or zmq' do
30
+ [:socket, :zmq].each do |type|
31
+ described_class.connector_type = type
32
+ described_class.connector_type.should eq type
33
+ end
34
+ end
35
+
36
+ it 'does not accept other types' do
37
+ [:hello, :world, :evented].each do |type|
38
+ expect {
39
+ described_class.connector_type = type
40
+ }.to raise_error(ArgumentError)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '.gc_pause_server_request?' do
46
+ before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) }
47
+
48
+ it 'defaults to a false value' do
49
+ described_class.gc_pause_server_request?.should be_false
50
+ end
51
+
52
+ it 'is settable' do
53
+ described_class.gc_pause_server_request = true
54
+ described_class.gc_pause_server_request?.should be_true
55
+ end
56
+ end
57
+
58
+ describe '.print_deprecation_warnings?' do
59
+ before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) }
60
+
61
+ it 'defaults to a true value' do
62
+ described_class.print_deprecation_warnings?.should be_true
63
+ end
64
+
65
+ it 'is settable' do
66
+ described_class.print_deprecation_warnings = false
67
+ described_class.print_deprecation_warnings?.should be_false
68
+ end
69
+
70
+ context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do
71
+ it 'defaults to a false value' do
72
+ ENV['PB_IGNORE_DEPRECATIONS'] = '1'
73
+ described_class.print_deprecation_warnings?.should be_false
74
+ end
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,57 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'timeout'
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ Bundler.setup :default, :development, :test
8
+ require 'pry'
9
+
10
+ $: << ::File.expand_path('../..', __FILE__)
11
+ $: << ::File.expand_path('../support', __FILE__)
12
+
13
+ require 'protobuf'
14
+ require 'protobuf/rpc/server'
15
+ require ::File.expand_path('../support/all', __FILE__)
16
+
17
+ $: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__)
18
+ require 'google/protobuf/compiler/plugin.pb'
19
+
20
+ # Including a way to turn on debug logger for spec runs
21
+ if ENV.key?('DEBUG')
22
+ debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) )
23
+ ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG)
24
+ end
25
+
26
+ # Get rid of the deprecation env var if present (messes with specs).
27
+ ENV.delete("PB_IGNORE_DEPRECATIONS")
28
+
29
+ ::RSpec.configure do |c|
30
+ c.include(::Sander6::CustomMatchers)
31
+ c.mock_with :rspec
32
+
33
+ c.before(:suite) do
34
+ unless ENV['NO_COMPILE_TEST_PROTOS']
35
+ require 'rake'
36
+ load ::File.expand_path('../../Rakefile', __FILE__)
37
+ $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)'
38
+ ::Rake::Task['compile:spec']
39
+ end
40
+ end
41
+ end
42
+
43
+ support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__)
44
+ Dir[support_proto_glob].each { |proto_file| require proto_file }
45
+
46
+ class ::Protobuf::Rpc::Client
47
+ def ==(other)
48
+ connector.options == other.options && \
49
+ success_cb == other.success_cb && \
50
+ failure_cb == other.failure_cb
51
+ end
52
+ end
53
+
54
+ def reset_service_location(service)
55
+ service.host = nil
56
+ service.port = nil
57
+ end