protobuf 1.4.2 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/.gitignore +4 -0
  2. data/Rakefile +7 -7
  3. data/bin/rpc_server +2 -188
  4. data/bin/rprotoc +44 -38
  5. data/examples/addressbook.pb.rb +2 -2
  6. data/ext/Makefile +11 -0
  7. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
  8. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
  9. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
  10. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
  11. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
  12. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
  13. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
  14. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  15. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
  16. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
  17. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
  18. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
  19. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  20. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
  21. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
  22. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
  23. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
  24. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
  25. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
  26. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
  27. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
  28. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
  29. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
  30. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
  31. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
  32. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
  33. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
  34. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
  35. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
  36. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
  37. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
  38. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
  39. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
  40. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
  41. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
  42. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
  43. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
  44. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
  45. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
  46. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
  47. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
  48. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
  49. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
  50. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
  51. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
  52. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
  53. data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
  54. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
  55. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
  56. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
  57. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
  58. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
  59. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
  60. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
  61. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
  62. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
  63. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
  64. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
  65. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
  66. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
  67. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
  68. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
  69. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
  70. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
  71. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
  72. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
  73. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
  74. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
  75. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
  76. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
  77. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
  78. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
  79. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
  80. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
  81. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
  82. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
  83. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
  84. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
  85. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
  86. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
  87. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
  88. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
  89. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
  90. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
  91. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
  92. data/ext/ruby_generator/RubyGenerator.cpp +435 -0
  93. data/ext/ruby_generator/RubyGenerator.h +180 -0
  94. data/ext/ruby_generator/extconf.rb +24 -0
  95. data/lib/protobuf.rb +55 -33
  96. data/lib/protobuf/cli.rb +176 -0
  97. data/lib/protobuf/common/logger.rb +11 -11
  98. data/lib/protobuf/{message/enum.rb → enum.rb} +0 -10
  99. data/lib/protobuf/evented.rb +22 -0
  100. data/lib/protobuf/field.rb +57 -0
  101. data/lib/protobuf/field/base_field.rb +210 -0
  102. data/lib/protobuf/field/bool_field.rb +24 -0
  103. data/lib/protobuf/field/bytes_field.rb +38 -0
  104. data/lib/protobuf/field/double_field.rb +19 -0
  105. data/lib/protobuf/field/enum_field.rb +58 -0
  106. data/lib/protobuf/field/extension_fields.rb +24 -0
  107. data/lib/protobuf/field/field_array.rb +55 -0
  108. data/lib/protobuf/field/fixed32_field.rb +19 -0
  109. data/lib/protobuf/field/fixed64_field.rb +22 -0
  110. data/lib/protobuf/field/float_field.rb +29 -0
  111. data/lib/protobuf/field/int32_field.rb +10 -0
  112. data/lib/protobuf/field/int64_field.rb +10 -0
  113. data/lib/protobuf/field/integer_field.rb +19 -0
  114. data/lib/protobuf/field/message_field.rb +51 -0
  115. data/lib/protobuf/field/sfixed32_field.rb +21 -0
  116. data/lib/protobuf/field/sfixed64_field.rb +24 -0
  117. data/lib/protobuf/field/signed_integer_field.rb +23 -0
  118. data/lib/protobuf/field/sint32_field.rb +10 -0
  119. data/lib/protobuf/field/sint64_field.rb +10 -0
  120. data/lib/protobuf/field/string_field.rb +14 -0
  121. data/lib/protobuf/field/uint32_field.rb +10 -0
  122. data/lib/protobuf/field/uint64_field.rb +10 -0
  123. data/lib/protobuf/field/varint_field.rb +63 -0
  124. data/lib/protobuf/message.rb +376 -0
  125. data/lib/protobuf/message/message.rb +1 -475
  126. data/lib/protobuf/rpc/buffer.rb +1 -1
  127. data/lib/protobuf/rpc/client.rb +26 -26
  128. data/lib/protobuf/rpc/connector.rb +15 -14
  129. data/lib/protobuf/rpc/connectors/eventmachine.rb +13 -13
  130. data/lib/protobuf/rpc/rpc.pb.rb +39 -28
  131. data/lib/protobuf/rpc/server.rb +7 -28
  132. data/lib/protobuf/rpc/servers/evented_runner.rb +15 -15
  133. data/lib/protobuf/rpc/servers/socket/server.rb +2 -1
  134. data/lib/protobuf/rpc/servers/socket_runner.rb +5 -6
  135. data/lib/protobuf/rpc/servers/zmq_runner.rb +4 -5
  136. data/lib/protobuf/socket.rb +22 -0
  137. data/lib/protobuf/version.rb +2 -1
  138. data/lib/protobuf/zmq.rb +21 -0
  139. data/proto/rpc.pb.rb +48 -0
  140. data/protobuf.gemspec +14 -6
  141. data/spec/benchmark/tasks.rb +42 -23
  142. data/spec/functional/evented_server_spec.rb +2 -0
  143. data/spec/functional/socket_server_spec.rb +22 -26
  144. data/spec/functional/zmq_server_spec.rb +22 -26
  145. data/spec/lib/protobuf/cli_spec.rb +182 -0
  146. data/spec/{unit → lib/protobuf}/common/logger_spec.rb +0 -0
  147. data/spec/{unit → lib/protobuf/message}/enum_spec.rb +0 -0
  148. data/spec/{unit → lib/protobuf/message}/message_spec.rb +0 -0
  149. data/spec/{unit → lib/protobuf}/rpc/client_spec.rb +6 -4
  150. data/spec/lib/protobuf/rpc/connector_spec.rb +41 -0
  151. data/spec/{unit → lib/protobuf}/rpc/connectors/base_spec.rb +18 -18
  152. data/spec/{unit → lib/protobuf}/rpc/connectors/common_spec.rb +20 -20
  153. data/spec/{unit → lib/protobuf}/rpc/connectors/socket_spec.rb +9 -8
  154. data/spec/{unit → lib/protobuf}/rpc/connectors/zmq_spec.rb +1 -1
  155. data/spec/{unit → lib/protobuf}/rpc/servers/evented_server_spec.rb +4 -4
  156. data/spec/{unit → lib/protobuf}/rpc/servers/socket_server_spec.rb +11 -23
  157. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/broker_spec.rb +5 -0
  158. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/server_spec.rb +5 -0
  159. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/util_spec.rb +5 -0
  160. data/spec/{unit → lib/protobuf}/rpc/servers/zmq/worker_spec.rb +5 -0
  161. data/spec/{unit → lib/protobuf}/rpc/service_spec.rb +0 -0
  162. data/spec/proto/test.pb.rb +48 -25
  163. data/spec/spec_helper.rb +9 -15
  164. data/spec/support/all.rb +7 -0
  165. data/spec/{helper → support}/server.rb +5 -7
  166. data/spec/{helper → support}/silent_constants.rb +4 -0
  167. data/spec/support/test_app_file.rb +2 -0
  168. data/spec/{helper → support}/tolerance_matcher.rb +0 -0
  169. data/test/proto/types.pb.rb +1 -1
  170. data/test/test_addressbook.rb +1 -1
  171. data/test/test_enum_value.rb +1 -1
  172. data/test/test_standard_message.rb +1 -1
  173. metadata +243 -107
  174. data/lib/protobuf/common/util.rb +0 -59
  175. data/lib/protobuf/compiler/compiler.rb +0 -52
  176. data/lib/protobuf/compiler/nodes.rb +0 -323
  177. data/lib/protobuf/compiler/proto.y +0 -216
  178. data/lib/protobuf/compiler/proto2.ebnf +0 -79
  179. data/lib/protobuf/compiler/proto_parser.rb +0 -1425
  180. data/lib/protobuf/compiler/template/rpc_service_implementation.erb +0 -42
  181. data/lib/protobuf/compiler/visitors.rb +0 -282
  182. data/lib/protobuf/descriptor/descriptor.proto +0 -286
  183. data/lib/protobuf/descriptor/descriptor.rb +0 -55
  184. data/lib/protobuf/descriptor/descriptor_builder.rb +0 -143
  185. data/lib/protobuf/descriptor/descriptor_proto.rb +0 -138
  186. data/lib/protobuf/descriptor/enum_descriptor.rb +0 -33
  187. data/lib/protobuf/descriptor/field_descriptor.rb +0 -49
  188. data/lib/protobuf/descriptor/file_descriptor.rb +0 -37
  189. data/lib/protobuf/message/field.rb +0 -684
  190. data/lib/protobuf/message/protoable.rb +0 -38
  191. data/spec/helper/all.rb +0 -7
  192. data/spec/unit/common/util_spec.rb +0 -17
  193. data/spec/unit/rpc/connector_spec.rb +0 -31
  194. data/spec/unit/rpc/connectors/eventmachine_client_spec.rb +0 -32
  195. data/spec/unit/rpc/connectors/eventmachine_spec.rb +0 -0
  196. data/test/check_unbuild.rb +0 -30
  197. data/test/test_compiler.rb +0 -325
  198. data/test/test_descriptor.rb +0 -122
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+ require 'protobuf/cli'
3
+
4
+ describe ::Protobuf::CLI do
5
+
6
+ let(:app_file) do
7
+ File.expand_path('../../../support/test_app_file.rb', __FILE__)
8
+ end
9
+
10
+ before do
11
+ ::Protobuf::Rpc::SocketRunner.stub(:run)
12
+ ::Protobuf::Rpc::ZmqRunner.stub(:run)
13
+ ::Protobuf::Rpc::EventedRunner.stub(:run)
14
+ end
15
+
16
+ describe '#start' do
17
+ let(:base_args) { [ 'start', app_file ] }
18
+ let(:test_args) { [] }
19
+ let(:args) { base_args + test_args }
20
+
21
+ context 'host option' do
22
+ let(:test_args) { [ '--host=123.123.123.123' ] }
23
+
24
+ it 'sends the host option to the runner' do
25
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
26
+ options.host.should eq '123.123.123.123'
27
+ end
28
+ described_class.start(args)
29
+ end
30
+ end
31
+
32
+ context 'port option' do
33
+ let(:test_args) { [ '--port=12345' ] }
34
+
35
+ it 'sends the port option to the runner' do
36
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
37
+ options.port.should eq 12345
38
+ end
39
+ described_class.start(args)
40
+ end
41
+ end
42
+
43
+ context 'backlog option' do
44
+ let(:test_args) { [ '--backlog=500' ] }
45
+
46
+ it 'sends the backlog option to the runner' do
47
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
48
+ options.backlog.should eq 500
49
+ end
50
+ described_class.start(args)
51
+ end
52
+ end
53
+
54
+ context 'threshold option' do
55
+ let(:test_args) { [ '--threshold=500' ] }
56
+
57
+ it 'sends the backlog option to the runner' do
58
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
59
+ options.threshold.should eq 500
60
+ end
61
+ described_class.start(args)
62
+ end
63
+ end
64
+
65
+ context 'log options' do
66
+ let(:test_args) { [ '--log=mylog.log', '--level=0' ] }
67
+
68
+ it 'sends the log file and level options to the runner' do
69
+ ::Protobuf::Logger.should_receive(:configure) do |options|
70
+ options[:file].should eq 'mylog.log'
71
+ options[:level].should eq 0
72
+ end
73
+ described_class.start(args)
74
+ end
75
+
76
+ context 'when debugging' do
77
+ let(:test_args) { [ '--level=3', '--debug' ] }
78
+
79
+ it 'overrides the log-level to DEBUG' do
80
+ ::Protobuf::Logger.should_receive(:configure) do |options|
81
+ options[:level].should eq ::Logger::DEBUG
82
+ end
83
+ described_class.start(args)
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'gc options' do
89
+
90
+ context 'when gc options are not present' do
91
+ let(:test_args) { [] }
92
+
93
+ it 'sets both request and serialization pausing to false' do
94
+ described_class.start(args)
95
+ ::Protobuf.gc_pause_server_request.should be_false
96
+ ::Protobuf.gc_pause_server_serialization.should be_false
97
+ end
98
+ end
99
+
100
+ context 'request pausing' do
101
+ let(:test_args) { [ '--gc_pause_request' ] }
102
+
103
+ it 'sets the configuration option to GC pause server request' do
104
+ described_class.start(args)
105
+ ::Protobuf.gc_pause_server_request.should be_true
106
+ end
107
+ end
108
+
109
+ context 'serialization pausing' do
110
+ let(:test_args) { [ '--gc_pause_serialization' ] }
111
+
112
+ it 'sets the configuration option to GC pause server serializations' do
113
+ described_class.start(args)
114
+ ::Protobuf.gc_pause_server_serialization.should be_true
115
+ end
116
+ end
117
+ end
118
+
119
+ context 'run modes' do
120
+
121
+ context 'socket' do
122
+ let(:test_args) { [ '--socket' ] }
123
+
124
+ before do
125
+ ::Protobuf::Rpc::EventedRunner.should_not_receive(:run)
126
+ ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run)
127
+ end
128
+
129
+ it 'is activated by the --socket switch' do
130
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run)
131
+ described_class.start(args)
132
+ end
133
+
134
+ it 'configures the connector type to be socket' do
135
+ load "protobuf/socket.rb"
136
+ ::Protobuf.connector_type.should == :socket
137
+ end
138
+ end
139
+
140
+ context 'evented' do
141
+ let(:test_args) { [ '--evented' ] }
142
+
143
+ before do
144
+ ::Protobuf::Rpc::SocketRunner.should_not_receive(:run)
145
+ ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run)
146
+ end
147
+
148
+ it 'is activated by the --evented switch' do
149
+ ::Protobuf::Rpc::EventedRunner.should_receive(:run)
150
+ described_class.start(args)
151
+ end
152
+
153
+ it 'configures the connector type to be evented' do
154
+ load "protobuf/evented.rb"
155
+ ::Protobuf.connector_type.should == :evented
156
+ end
157
+ end
158
+
159
+ context 'zmq' do
160
+ let(:test_args) { [ '--zmq' ] }
161
+
162
+ before do
163
+ ::Protobuf::Rpc::SocketRunner.should_not_receive(:run)
164
+ ::Protobuf::Rpc::EventedRunner.should_not_receive(:run)
165
+ end
166
+
167
+ it 'is activated by the --zmq switch' do
168
+ ::Protobuf::Rpc::ZmqRunner.should_receive(:run)
169
+ described_class.start(args)
170
+ end
171
+
172
+ it 'configures the connector type to be zmq' do
173
+ load "protobuf/zmq.rb"
174
+ ::Protobuf.connector_type.should == :zmq
175
+ end
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+
182
+ end
@@ -3,6 +3,8 @@ require 'spec/proto/test_service_impl'
3
3
 
4
4
  describe Protobuf::Rpc::Client do
5
5
  before(:each) do
6
+ load 'protobuf/evented.rb'
7
+ ::Protobuf::Rpc::Connector.connector_for_client(true)
6
8
  ::Spec::Proto::TestService.configure(::Spec::Proto::TestService::DEFAULT_LOCATION)
7
9
  end
8
10
 
@@ -16,8 +18,8 @@ describe Protobuf::Rpc::Client do
16
18
  client.find(:name => "Test Name", :active => true) do |c|
17
19
  c.on_success do |succ|
18
20
  succ.name.should eq("Test Name")
19
- succ.status.should eq(Spec::Proto::StatusType::ENABLED)
20
- end
21
+ succ.status.should eq(Spec::Proto::StatusType::ENABLED)
22
+ end
21
23
 
22
24
  c.on_failure do |err|
23
25
  raise err.inspect
@@ -76,7 +78,7 @@ describe Protobuf::Rpc::Client do
76
78
  error.message.should =~ /timeout/i
77
79
  end
78
80
 
79
- context "without reactor_running?" do
81
+ context "without reactor_running?" do
80
82
 
81
83
  it "throws a timeout when client timeout is exceeded" do
82
84
  subject = Proc.new do
@@ -154,7 +156,7 @@ describe Protobuf::Rpc::Client do
154
156
 
155
157
  context 'when calling methods on a service client' do
156
158
 
157
- # NOTE: we are assuming the service methods are accurately
159
+ # NOTE: we are assuming the service methods are accurately
158
160
  # defined inside spec/proto/test_service.rb,
159
161
  # namely the :find method
160
162
 
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'protobuf/socket'
3
+ require 'protobuf/evented'
4
+ require 'protobuf/zmq'
5
+
6
+ describe ::Protobuf::Rpc::Connector do
7
+
8
+ describe '.connector_for_client(true)' do
9
+ after { described_class.instance_variable_set(:@_connector, nil) }
10
+
11
+ context 'Protobuf.connector_type is socket' do
12
+ it 'returns a socket connector class' do
13
+ ::Protobuf.connector_type = :socket
14
+ described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket
15
+ end
16
+ end
17
+
18
+ context 'Protobuf.connector_type is not a known value' do
19
+ it 'returns a socket connector class' do
20
+ ::Protobuf.stub(:connector_type).and_return('some value')
21
+ described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket
22
+ end
23
+ end
24
+
25
+ context 'Protobuf.connector_type is evented' do
26
+ it 'returns an eventmachine connector class' do
27
+ ::Protobuf.connector_type = :evented
28
+ described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::EventMachine
29
+ end
30
+ end
31
+
32
+ context 'Protobuf.connector_type is zmq' do
33
+ it 'returns a zmq connector class' do
34
+ ::Protobuf.connector_type = :zmq
35
+ described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Zmq
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Protobuf::Rpc::Connectors::Base do
4
-
4
+
5
5
  let(:opts) do
6
6
  { async: false, timeout: 60 }
7
7
  end
8
-
8
+
9
9
  subject { Protobuf::Rpc::Connectors::Base.new(opts) }
10
-
11
- describe "#send_request" do
12
- it "raising an error when 'send_request' is not overridden" do
10
+
11
+ describe "#send_request" do
12
+ it "raising an error when 'send_request' is not overridden" do
13
13
  expect{ subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/)
14
14
  end
15
15
 
16
- it "does not raise error when 'send_request' is overridden" do
16
+ it "does not raise error when 'send_request' is overridden" do
17
17
  new_sub = Class.new(subject.class){ def send_request; end }.new(opts)
18
18
  expect{ new_sub.send_request }.to_not raise_error
19
19
  end
@@ -26,7 +26,7 @@ describe Protobuf::Rpc::Connectors::Base do
26
26
  subject.failure_cb.should be_nil
27
27
  end
28
28
  end
29
-
29
+
30
30
  describe '#success_cb' do
31
31
  it 'allows setting the success callback and calling it' do
32
32
  subject.success_cb.should be_nil
@@ -36,7 +36,7 @@ describe Protobuf::Rpc::Connectors::Base do
36
36
  expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb'
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe '#failure_cb' do
41
41
  it 'allows setting the failure callback and calling it' do
42
42
  subject.failure_cb.should be_nil
@@ -46,43 +46,43 @@ describe Protobuf::Rpc::Connectors::Base do
46
46
  expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb'
47
47
  end
48
48
  end
49
-
49
+
50
50
  describe '#async?' do
51
51
  context 'when provided options[:async] is false' do
52
52
  let(:opts) do
53
53
  { async: false, timeout: 60 }
54
54
  end
55
-
55
+
56
56
  subject { Protobuf::Rpc::Connectors::Base.new(opts) }
57
-
57
+
58
58
  it 'returns false' do
59
59
  subject.async?.should be_false
60
60
  end
61
61
  end
62
-
62
+
63
63
  context 'when provided options[:async] is true' do
64
64
  let(:opts) do
65
65
  { async: true, timeout: 60 }
66
66
  end
67
-
67
+
68
68
  subject { Protobuf::Rpc::Connectors::Base.new(opts) }
69
-
69
+
70
70
  it 'returns true' do
71
71
  subject.async?.should be_true
72
72
  end
73
73
  end
74
-
74
+
75
75
  context 'when options doesn\'t denote async' do
76
76
  let(:opts) do
77
77
  { timeout: 60 }
78
78
  end
79
-
79
+
80
80
  subject { Protobuf::Rpc::Connectors::Base.new(opts) }
81
-
81
+
82
82
  it 'returns false' do
83
83
  subject.async?.should be_false
84
84
  end
85
85
  end
86
86
  end
87
-
87
+
88
88
  end
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
2
- require 'protobuf/rpc/service'
1
+ require 'spec_helper'
2
+ require 'protobuf/rpc/service'
3
3
 
4
4
  describe Protobuf::Rpc::Connectors::Common do
5
- let(:common_class) do
5
+ let(:common_class) do
6
6
  Class.new(Protobuf::Rpc::Connectors::Base) do
7
- include Protobuf::Rpc::Connectors::Common
7
+ include Protobuf::Rpc::Connectors::Common
8
8
  attr_accessor :options
9
9
  attr_accessor :stats
10
10
  end
@@ -12,7 +12,7 @@ describe Protobuf::Rpc::Connectors::Common do
12
12
 
13
13
  subject{ @subject ||= common_class.new({}) }
14
14
 
15
- context "API" do
15
+ context "API" do
16
16
  specify{ subject.respond_to?(:any_callbacks?).should be_true }
17
17
  specify{ subject.respond_to?(:data_callback).should be_true }
18
18
  specify{ subject.respond_to?(:error).should be_true }
@@ -23,16 +23,16 @@ describe Protobuf::Rpc::Connectors::Common do
23
23
  specify{ subject.respond_to?(:verify_callbacks).should be_true }
24
24
  end
25
25
 
26
- context "#any_callbacks?" do
26
+ context "#any_callbacks?" do
27
27
 
28
28
  [:@complete_cb, :@success_cb, :@failure_cb].each do |cb|
29
- it "returns true if #{cb} is provided" do
29
+ it "returns true if #{cb} is provided" do
30
30
  subject.instance_variable_set(cb, "something")
31
31
  subject.any_callbacks?.should be_true
32
32
  end
33
33
  end
34
34
 
35
- it "returns false when all callbacks are not provided" do
35
+ it "returns false when all callbacks are not provided" do
36
36
  subject.instance_variable_set(:@complete_cb, nil)
37
37
  subject.instance_variable_set(:@success_cb, nil)
38
38
  subject.instance_variable_set(:@failure_cb, nil)
@@ -42,31 +42,31 @@ describe Protobuf::Rpc::Connectors::Common do
42
42
 
43
43
  end
44
44
 
45
- context "#data_callback" do
45
+ context "#data_callback" do
46
46
  it "changes state to use the data callback" do
47
47
  subject.data_callback("data")
48
48
  subject.instance_variable_get(:@used_data_callback).should be_true
49
49
  end
50
50
 
51
- it "sets the data var when using the data_callback" do
51
+ it "sets the data var when using the data_callback" do
52
52
  subject.data_callback("data")
53
53
  subject.instance_variable_get(:@data).should eq("data")
54
54
  end
55
55
  end
56
56
 
57
- context "#verify_callbacks" do
57
+ context "#verify_callbacks" do
58
58
 
59
- it "sets @failure_cb to #data_callback when no callbacks are defined" do
59
+ it "sets @failure_cb to #data_callback when no callbacks are defined" do
60
60
  subject.verify_callbacks
61
- subject.instance_variable_get(:@failure_cb).should eq(subject.method(:data_callback))
61
+ subject.instance_variable_get(:@failure_cb).should eq(subject.method(:data_callback))
62
62
  end
63
63
 
64
64
  it "sets @success_cb to #data_callback when no callbacks are defined" do
65
65
  subject.verify_callbacks
66
- subject.instance_variable_get(:@success_cb).should eq(subject.method(:data_callback))
66
+ subject.instance_variable_get(:@success_cb).should eq(subject.method(:data_callback))
67
67
  end
68
68
 
69
- it "doesn't set @failure_cb when already defined" do
69
+ it "doesn't set @failure_cb when already defined" do
70
70
  set_cb = lambda{ true }
71
71
  subject.instance_variable_set(:@failure_cb, set_cb)
72
72
  subject.verify_callbacks
@@ -74,7 +74,7 @@ describe Protobuf::Rpc::Connectors::Common do
74
74
  subject.instance_variable_get(:@failure_cb).should_not eq(subject.method(:data_callback))
75
75
  end
76
76
 
77
- it "doesn't set @success_cb when already defined" do
77
+ it "doesn't set @success_cb when already defined" do
78
78
  set_cb = lambda{ true }
79
79
  subject.instance_variable_set(:@success_cb, set_cb)
80
80
  subject.verify_callbacks
@@ -86,7 +86,7 @@ describe Protobuf::Rpc::Connectors::Common do
86
86
 
87
87
  shared_examples "a ConnectorDisposition" do |meth, cb, *args|
88
88
 
89
- it "calls #complete before exit" do
89
+ it "calls #complete before exit" do
90
90
  stats = double("Object")
91
91
  stats.stub(:end) { true }
92
92
  stats.stub(:log_stats) { true }
@@ -96,7 +96,7 @@ describe Protobuf::Rpc::Connectors::Common do
96
96
  subject.method(meth).call(*args)
97
97
  end
98
98
 
99
- it "calls the #{cb} callback when provided" do
99
+ it "calls the #{cb} callback when provided" do
100
100
  stats = double("Object")
101
101
  stats.stub(:end) { true }
102
102
  stats.stub(:log_stats) { true }
@@ -108,13 +108,13 @@ describe Protobuf::Rpc::Connectors::Common do
108
108
  subject.method(meth).call(*args)
109
109
  end
110
110
 
111
- it "calls the complete callback when provided" do
111
+ it "calls the complete callback when provided" do
112
112
  stats = double("Object")
113
113
  stats.stub(:end) { true }
114
114
  stats.stub(:log_stats) { true }
115
115
  subject.stats = stats
116
116
  comp_cb = double("Object")
117
-
117
+
118
118
  subject.instance_variable_set(:@complete_cb, comp_cb)
119
119
  comp_cb.should_receive(:call).and_return(true)
120
120
  subject.method(meth).call(*args)