protobuf 2.2.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +9 -0
  3. data/.yardopts +5 -0
  4. data/Gemfile +3 -0
  5. data/README.md +316 -0
  6. data/Rakefile +29 -0
  7. data/UPGRADING.md +60 -0
  8. data/bin/rpc_server +5 -0
  9. data/bin/rprotoc +62 -0
  10. data/examples/addressbook.pb.rb +55 -0
  11. data/examples/addressbook.proto +24 -0
  12. data/examples/reading_a_message.rb +32 -0
  13. data/examples/writing_a_message.rb +46 -0
  14. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
  15. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
  16. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
  17. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
  18. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
  19. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
  20. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
  21. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  22. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
  23. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
  24. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
  25. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
  26. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  27. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
  28. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
  29. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
  30. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
  31. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
  32. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
  33. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
  34. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
  35. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
  36. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
  37. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
  38. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
  39. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
  40. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
  41. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
  42. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
  43. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
  44. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
  45. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
  46. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
  47. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
  48. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
  49. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
  50. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
  51. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
  52. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
  53. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
  54. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
  55. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
  56. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
  57. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
  58. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
  59. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
  60. data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
  61. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
  62. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
  63. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
  64. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
  65. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
  66. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
  67. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
  68. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
  69. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
  70. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
  71. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
  72. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
  73. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
  74. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
  75. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
  76. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
  77. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
  78. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
  79. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
  80. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
  81. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
  82. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
  83. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
  84. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
  85. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
  86. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
  87. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
  88. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
  89. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
  90. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
  91. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
  92. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
  93. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
  94. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
  95. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
  96. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
  97. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
  98. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
  99. data/ext/ruby_generator/Makefile +10 -0
  100. data/ext/ruby_generator/RubyGenerator.cpp +450 -0
  101. data/ext/ruby_generator/RubyGenerator.h +199 -0
  102. data/ext/ruby_generator/extconf.rb +36 -0
  103. data/ext/ruby_generator/protoc-ruby +0 -0
  104. data/lib/protobuf/cli.rb +188 -0
  105. data/lib/protobuf/enum.rb +58 -0
  106. data/lib/protobuf/enum_value.rb +59 -0
  107. data/lib/protobuf/evented.rb +22 -0
  108. data/lib/protobuf/exceptions.rb +11 -0
  109. data/lib/protobuf/ext/eventmachine.rb +14 -0
  110. data/lib/protobuf/field/base_field.rb +240 -0
  111. data/lib/protobuf/field/bool_field.rb +36 -0
  112. data/lib/protobuf/field/bytes_field.rb +38 -0
  113. data/lib/protobuf/field/double_field.rb +19 -0
  114. data/lib/protobuf/field/enum_field.rb +50 -0
  115. data/lib/protobuf/field/extension_fields.rb +32 -0
  116. data/lib/protobuf/field/field_array.rb +65 -0
  117. data/lib/protobuf/field/fixed32_field.rb +19 -0
  118. data/lib/protobuf/field/fixed64_field.rb +22 -0
  119. data/lib/protobuf/field/float_field.rb +31 -0
  120. data/lib/protobuf/field/int32_field.rb +12 -0
  121. data/lib/protobuf/field/int64_field.rb +12 -0
  122. data/lib/protobuf/field/integer_field.rb +19 -0
  123. data/lib/protobuf/field/message_field.rb +53 -0
  124. data/lib/protobuf/field/sfixed32_field.rb +21 -0
  125. data/lib/protobuf/field/sfixed64_field.rb +24 -0
  126. data/lib/protobuf/field/signed_integer_field.rb +23 -0
  127. data/lib/protobuf/field/sint32_field.rb +12 -0
  128. data/lib/protobuf/field/sint64_field.rb +12 -0
  129. data/lib/protobuf/field/string_field.rb +14 -0
  130. data/lib/protobuf/field/uint32_field.rb +12 -0
  131. data/lib/protobuf/field/uint64_field.rb +12 -0
  132. data/lib/protobuf/field/varint_field.rb +61 -0
  133. data/lib/protobuf/field.rb +57 -0
  134. data/lib/protobuf/logger.rb +86 -0
  135. data/lib/protobuf/message/decoder.rb +83 -0
  136. data/lib/protobuf/message/encoder.rb +48 -0
  137. data/lib/protobuf/message/extend.rb +8 -0
  138. data/lib/protobuf/message/message.rb +1 -0
  139. data/lib/protobuf/message.rb +320 -0
  140. data/lib/protobuf/rpc/buffer.rb +79 -0
  141. data/lib/protobuf/rpc/client.rb +166 -0
  142. data/lib/protobuf/rpc/connector.rb +19 -0
  143. data/lib/protobuf/rpc/connectors/base.rb +38 -0
  144. data/lib/protobuf/rpc/connectors/common.rb +156 -0
  145. data/lib/protobuf/rpc/connectors/em_client.rb +84 -0
  146. data/lib/protobuf/rpc/connectors/eventmachine.rb +87 -0
  147. data/lib/protobuf/rpc/connectors/socket.rb +73 -0
  148. data/lib/protobuf/rpc/connectors/zmq.rb +69 -0
  149. data/lib/protobuf/rpc/error/client_error.rb +31 -0
  150. data/lib/protobuf/rpc/error/server_error.rb +43 -0
  151. data/lib/protobuf/rpc/error.rb +25 -0
  152. data/lib/protobuf/rpc/rpc.pb.rb +118 -0
  153. data/lib/protobuf/rpc/server.rb +89 -0
  154. data/lib/protobuf/rpc/servers/evented/server.rb +41 -0
  155. data/lib/protobuf/rpc/servers/evented_runner.rb +21 -0
  156. data/lib/protobuf/rpc/servers/socket/server.rb +111 -0
  157. data/lib/protobuf/rpc/servers/socket/worker.rb +66 -0
  158. data/lib/protobuf/rpc/servers/socket_runner.rb +27 -0
  159. data/lib/protobuf/rpc/servers/zmq/broker.rb +87 -0
  160. data/lib/protobuf/rpc/servers/zmq/server.rb +50 -0
  161. data/lib/protobuf/rpc/servers/zmq/util.rb +27 -0
  162. data/lib/protobuf/rpc/servers/zmq/worker.rb +60 -0
  163. data/lib/protobuf/rpc/servers/zmq_runner.rb +25 -0
  164. data/lib/protobuf/rpc/service.rb +173 -0
  165. data/lib/protobuf/rpc/service_dispatcher.rb +130 -0
  166. data/lib/protobuf/rpc/service_filters.rb +267 -0
  167. data/lib/protobuf/rpc/stat.rb +83 -0
  168. data/lib/protobuf/socket.rb +22 -0
  169. data/lib/protobuf/version.rb +4 -0
  170. data/lib/protobuf/wire_type.rb +10 -0
  171. data/lib/protobuf/zmq.rb +21 -0
  172. data/lib/protobuf.rb +86 -0
  173. data/proto/rpc.pb.rb +48 -0
  174. data/proto/rpc.proto +73 -0
  175. data/protobuf.gemspec +44 -0
  176. data/spec/benchmark/tasks.rb +179 -0
  177. data/spec/functional/embedded_service_spec.rb +7 -0
  178. data/spec/functional/evented_server_spec.rb +64 -0
  179. data/spec/functional/socket_server_spec.rb +58 -0
  180. data/spec/functional/zmq_server_spec.rb +58 -0
  181. data/spec/lib/protobuf/cli_spec.rb +212 -0
  182. data/spec/lib/protobuf/enum_spec.rb +98 -0
  183. data/spec/lib/protobuf/enum_value_spec.rb +15 -0
  184. data/spec/lib/protobuf/logger_spec.rb +131 -0
  185. data/spec/lib/protobuf/message/encoder_spec.rb +19 -0
  186. data/spec/lib/protobuf/message_spec.rb +209 -0
  187. data/spec/lib/protobuf/rpc/client_spec.rb +158 -0
  188. data/spec/lib/protobuf/rpc/connector_spec.rb +32 -0
  189. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
  190. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +128 -0
  191. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +36 -0
  192. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +22 -0
  193. data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +18 -0
  194. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +43 -0
  195. data/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +35 -0
  196. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +41 -0
  197. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +45 -0
  198. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +44 -0
  199. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +116 -0
  200. data/spec/lib/protobuf/rpc/service_filters_spec.rb +451 -0
  201. data/spec/lib/protobuf/rpc/service_spec.rb +165 -0
  202. data/spec/lib/protobuf_spec.rb +62 -0
  203. data/spec/spec_helper.rb +51 -0
  204. data/spec/support/all.rb +6 -0
  205. data/spec/support/server.rb +101 -0
  206. data/spec/support/test/enum.pb.rb +34 -0
  207. data/spec/support/test/enum.proto +12 -0
  208. data/spec/support/test/resource.pb.rb +58 -0
  209. data/spec/support/test/resource.proto +31 -0
  210. data/spec/support/test/resource_service.rb +14 -0
  211. data/spec/support/test_app_file.rb +2 -0
  212. data/spec/support/tolerance_matcher.rb +40 -0
  213. data/test/data/data.bin +3 -0
  214. data/test/data/data_source.py +14 -0
  215. data/test/data/types.bin +0 -0
  216. data/test/data/types_source.py +22 -0
  217. data/test/data/unk.png +0 -0
  218. data/test/proto/addressbook.pb.rb +66 -0
  219. data/test/proto/addressbook.proto +33 -0
  220. data/test/proto/addressbook_base.pb.rb +58 -0
  221. data/test/proto/addressbook_base.proto +26 -0
  222. data/test/proto/addressbook_ext.pb.rb +20 -0
  223. data/test/proto/addressbook_ext.proto +6 -0
  224. data/test/proto/collision.pb.rb +17 -0
  225. data/test/proto/collision.proto +5 -0
  226. data/test/proto/ext_collision.pb.rb +24 -0
  227. data/test/proto/ext_collision.proto +8 -0
  228. data/test/proto/ext_range.pb.rb +22 -0
  229. data/test/proto/ext_range.proto +7 -0
  230. data/test/proto/float_default.proto +10 -0
  231. data/test/proto/lowercase.pb.rb +30 -0
  232. data/test/proto/lowercase.proto +9 -0
  233. data/test/proto/merge.pb.rb +39 -0
  234. data/test/proto/merge.proto +15 -0
  235. data/test/proto/nested.pb.rb +30 -0
  236. data/test/proto/nested.proto +9 -0
  237. data/test/proto/optional_field.pb.rb +35 -0
  238. data/test/proto/optional_field.proto +12 -0
  239. data/test/proto/packed.pb.rb +22 -0
  240. data/test/proto/packed.proto +6 -0
  241. data/test/proto/rpc.proto +6 -0
  242. data/test/proto/types.pb.rb +84 -0
  243. data/test/proto/types.proto +37 -0
  244. data/test/test_addressbook.rb +56 -0
  245. data/test/test_enum_value.rb +41 -0
  246. data/test/test_extension.rb +36 -0
  247. data/test/test_lowercase.rb +11 -0
  248. data/test/test_message.rb +128 -0
  249. data/test/test_optional_field.rb +103 -0
  250. data/test/test_packed_field.rb +40 -0
  251. data/test/test_parse.rb +15 -0
  252. data/test/test_repeated_types.rb +132 -0
  253. data/test/test_serialize.rb +61 -0
  254. data/test/test_standard_message.rb +96 -0
  255. data/test/test_types.rb +226 -0
  256. metadata +461 -0
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'spec/support/test/resource_service'
3
+
4
+ describe 'Functional Socket Client' do
5
+ before(:all) do
6
+ load "protobuf/socket.rb"
7
+ Thread.abort_on_exception = true
8
+ server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
9
+ @server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) }
10
+ Thread.pass until Protobuf::Rpc::Socket::Server.running?
11
+ end
12
+
13
+ after(:all) do
14
+ Protobuf::Rpc::SocketRunner.stop
15
+ @server_thread.join
16
+ end
17
+
18
+ it 'runs fine when required fields are set' do
19
+ expect {
20
+ client = ::Test::ResourceService.client
21
+
22
+ client.find(:name => 'Test Name', :active => true) do |c|
23
+ c.on_success do |succ|
24
+ succ.name.should eq("Test Name")
25
+ succ.status.should eq(::Test::StatusType::ENABLED)
26
+ end
27
+
28
+ c.on_failure do |err|
29
+ raise err.inspect
30
+ end
31
+ end
32
+ }.to_not raise_error
33
+ end
34
+
35
+ it 'calls the on_failure callback when a message is malformed' do
36
+ error = nil
37
+ request = ::Test::ResourceFindRequest.new(:active => true)
38
+ client = ::Test::ResourceService.client
39
+
40
+ client.find(request) do |c|
41
+ c.on_success { raise "shouldn't pass"}
42
+ c.on_failure {|e| error = e}
43
+ end
44
+ error.message.should =~ /ResourceFindRequest.*fields.*improperly set/
45
+ end
46
+
47
+ it 'calls the on_failure callback when the request type is wrong' do
48
+ error = nil
49
+ request = ::Test::Resource.new(:name => 'Test Name')
50
+ client = ::Test::ResourceService.client
51
+
52
+ client.find(request) do |c|
53
+ c.on_success { raise "shouldn't pass"}
54
+ c.on_failure {|e| error = e}
55
+ end
56
+ error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'spec/support/test/resource_service'
3
+
4
+ describe 'Functional ZMQ Client' do
5
+ before(:all) do
6
+ load "protobuf/zmq.rb"
7
+ Thread.abort_on_exception = true
8
+ server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5)
9
+ @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) }
10
+ Thread.pass until Protobuf::Rpc::Zmq::Server.running?
11
+ end
12
+
13
+ after(:all) do
14
+ ::Protobuf::Rpc::Zmq::Server.stop
15
+ @server_thread.join
16
+ end
17
+
18
+ it 'runs fine when required fields are set' do
19
+ expect {
20
+ client = ::Test::ResourceService.client
21
+
22
+ client.find(:name => 'Test Name', :active => true) do |c|
23
+ c.on_success do |succ|
24
+ succ.name.should eq("Test Name")
25
+ succ.status.should eq(::Test::StatusType::ENABLED)
26
+ end
27
+
28
+ c.on_failure do |err|
29
+ raise err.inspect
30
+ end
31
+ end
32
+ }.to_not raise_error
33
+ end
34
+
35
+ it 'calls the on_failure callback when a message is malformed' do
36
+ error = nil
37
+ request = ::Test::ResourceFindRequest.new(:active => true)
38
+ client = ::Test::ResourceService.client
39
+
40
+ client.find(request) do |c|
41
+ c.on_success { raise "shouldn't pass"}
42
+ c.on_failure {|e| error = e}
43
+ end
44
+ error.message.should =~ /ResourceFindRequest.*fields.*improperly set/
45
+ end
46
+
47
+ it 'calls the on_failure callback when the request type is wrong' do
48
+ error = nil
49
+ request = ::Test::Resource.new(:name => 'Test Name')
50
+ client = ::Test::ResourceService.client
51
+
52
+ client.find(request) do |c|
53
+ c.on_success { raise "shouldn't pass"}
54
+ c.on_failure {|e| error = e}
55
+ end
56
+ error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i
57
+ end
58
+ end
@@ -0,0 +1,212 @@
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 'threads option' do
44
+ let(:test_args) { [ '--threads=500' ] }
45
+
46
+ it 'sends the threads option to the runner' do
47
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
48
+ options[:threads].should eq 500
49
+ end
50
+ described_class.start(args)
51
+ end
52
+ end
53
+
54
+ context 'backlog option' do
55
+ let(:test_args) { [ '--backlog=500' ] }
56
+
57
+ it 'sends the backlog option to the runner' do
58
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
59
+ options[:backlog].should eq 500
60
+ end
61
+ described_class.start(args)
62
+ end
63
+ end
64
+
65
+ context 'threshold option' do
66
+ let(:test_args) { [ '--threshold=500' ] }
67
+
68
+ it 'sends the backlog option to the runner' do
69
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run) do |options|
70
+ options[:threshold].should eq 500
71
+ end
72
+ described_class.start(args)
73
+ end
74
+ end
75
+
76
+ context 'log options' do
77
+ let(:test_args) { [ '--log=mylog.log', '--level=0' ] }
78
+
79
+ it 'sends the log file and level options to the runner' do
80
+ ::Protobuf::Logger.should_receive(:configure) do |options|
81
+ options[:file].should eq 'mylog.log'
82
+ options[:level].should eq 0
83
+ end
84
+ described_class.start(args)
85
+ end
86
+
87
+ context 'when debugging' do
88
+ let(:test_args) { [ '--level=3', '--debug' ] }
89
+
90
+ it 'overrides the log-level to DEBUG' do
91
+ ::Protobuf::Logger.should_receive(:configure) do |options|
92
+ options[:level].should eq ::Logger::DEBUG
93
+ end
94
+ described_class.start(args)
95
+ end
96
+ end
97
+ end
98
+
99
+ context 'gc options' do
100
+
101
+ context 'when gc options are not present' do
102
+ let(:test_args) { [] }
103
+
104
+ it 'sets both request and serialization pausing to false' do
105
+ described_class.start(args)
106
+ ::Protobuf.gc_pause_server_request?.should be_false
107
+ end
108
+ end
109
+
110
+ context 'request pausing' do
111
+ let(:test_args) { [ '--gc_pause_request' ] }
112
+
113
+ it 'sets the configuration option to GC pause server request' do
114
+ described_class.start(args)
115
+ ::Protobuf.gc_pause_server_request?.should be_true
116
+ end
117
+ end
118
+ end
119
+
120
+ context 'deprecation options' do
121
+ context 'when not given' do
122
+ let(:test_args) { [] }
123
+
124
+ it 'sets the deprecation warning flag to its default value' do
125
+ described_class.start(args)
126
+ ::Protobuf.print_deprecation_warnings?.should be_true
127
+ end
128
+ end
129
+
130
+ context 'when enabled' do
131
+ let(:test_args) { [ '--print_deprecation_warnings' ] }
132
+
133
+ it 'sets the deprecation warning flag to true' do
134
+ described_class.start(args)
135
+ ::Protobuf.print_deprecation_warnings?.should be_true
136
+ end
137
+ end
138
+
139
+ context 'when disabled' do
140
+ let(:test_args) { [ '--no-print_deprecation_warnings' ] }
141
+
142
+ it 'sets the deprecation warning flag to false' do
143
+ described_class.start(args)
144
+ ::Protobuf.print_deprecation_warnings?.should be_false
145
+ end
146
+ end
147
+ end
148
+
149
+ context 'run modes' do
150
+
151
+ context 'socket' do
152
+ let(:test_args) { [ '--socket' ] }
153
+
154
+ before do
155
+ ::Protobuf::Rpc::EventedRunner.should_not_receive(:run)
156
+ ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run)
157
+ end
158
+
159
+ it 'is activated by the --socket switch' do
160
+ ::Protobuf::Rpc::SocketRunner.should_receive(:run)
161
+ described_class.start(args)
162
+ end
163
+
164
+ it 'configures the connector type to be socket' do
165
+ load "protobuf/socket.rb"
166
+ ::Protobuf.connector_type.should == :socket
167
+ end
168
+ end
169
+
170
+ context 'evented' do
171
+ let(:test_args) { [ '--evented' ] }
172
+
173
+ before do
174
+ ::Protobuf::Rpc::SocketRunner.should_not_receive(:run)
175
+ ::Protobuf::Rpc::ZmqRunner.should_not_receive(:run)
176
+ end
177
+
178
+ it 'is activated by the --evented switch' do
179
+ ::Protobuf::Rpc::EventedRunner.should_receive(:run)
180
+ described_class.start(args)
181
+ end
182
+
183
+ it 'configures the connector type to be evented' do
184
+ load "protobuf/evented.rb"
185
+ ::Protobuf.connector_type.should == :evented
186
+ end
187
+ end
188
+
189
+ context 'zmq' do
190
+ let(:test_args) { [ '--zmq' ] }
191
+
192
+ before do
193
+ ::Protobuf::Rpc::SocketRunner.should_not_receive(:run)
194
+ ::Protobuf::Rpc::EventedRunner.should_not_receive(:run)
195
+ end
196
+
197
+ it 'is activated by the --zmq switch' do
198
+ ::Protobuf::Rpc::ZmqRunner.should_receive(:run)
199
+ described_class.start(args)
200
+ end
201
+
202
+ it 'configures the connector type to be zmq' do
203
+ load "protobuf/zmq.rb"
204
+ ::Protobuf.connector_type.should == :zmq
205
+ end
206
+ end
207
+
208
+ end
209
+
210
+ end
211
+
212
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe Protobuf::Enum do
4
+ let(:name) { :THREE }
5
+ let(:tag) { 3 }
6
+
7
+ before(:all) do
8
+ Test::EnumTestType.define(name, tag)
9
+ end
10
+
11
+ describe '.define' do
12
+ it 'defines a constant enum value on the parent class' do
13
+ Test::EnumTestType.constants.should include(name)
14
+ Test::EnumTestType::THREE.should be_a(Protobuf::EnumValue)
15
+ end
16
+ end
17
+
18
+ describe '.fetch' do
19
+ context 'when value is an EnumValue' do
20
+ it 'responds with that object' do
21
+ Test::EnumTestType.fetch(Test::EnumTestType::THREE).should eq Test::EnumTestType::THREE
22
+ end
23
+ end
24
+
25
+ context 'when value can be coerced to a symbol' do
26
+ it 'fetches based on the symbol name value' do
27
+ Test::EnumTestType.fetch("ONE").should eq Test::EnumTestType::ONE
28
+ Test::EnumTestType.fetch(:ONE).should eq Test::EnumTestType::ONE
29
+ end
30
+ end
31
+
32
+ context 'when value can be coerced to an integer' do
33
+ it 'fetches based on the integer tag value' do
34
+ Test::EnumTestType.fetch(3.0).should eq Test::EnumTestType::THREE
35
+ Test::EnumTestType.fetch(3).should eq Test::EnumTestType::THREE
36
+ end
37
+ end
38
+
39
+ context 'when value is not an applicable type' do
40
+ it 'returns a nil' do
41
+ Test::EnumTestType.fetch(Test::Resource.new).should be_nil
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.enum_by_value' do
47
+ it 'gets the EnumValue corresponding to the given value (tag)' do
48
+ Test::EnumTestType.enum_by_value(tag).should eq Test::EnumTestType::THREE
49
+ end
50
+ end
51
+
52
+ describe '.name_by_value' do
53
+ it 'gets the name of the enum corresponding to the given value (tag)' do
54
+ Test::EnumTestType.name_by_value(tag).should eq name
55
+ end
56
+
57
+ context 'when given name is nil' do
58
+ it 'returns a nil' do
59
+ Test::EnumTestType.name_by_value(nil).should be_nil
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '.valid_tag?' do
65
+ context 'when tag is defined' do
66
+ specify { Test::EnumTestType.valid_tag?(tag).should be_true }
67
+ end
68
+
69
+ context 'when tag is not defined' do
70
+ specify { Test::EnumTestType.valid_tag?(300).should be_false }
71
+ end
72
+ end
73
+
74
+ describe '.value_by_name' do
75
+ it 'gets the EnumValue corresponding to the given name' do
76
+ Test::EnumTestType.value_by_name(name).should eq Test::EnumTestType::THREE
77
+ end
78
+ end
79
+
80
+ describe '.values' do
81
+ it 'provides a hash of defined EnumValues' do
82
+ Test::EnumTestType.values.should eq({
83
+ :ONE => Test::EnumTestType::ONE,
84
+ :TWO => Test::EnumTestType::TWO,
85
+ :THREE => Test::EnumTestType::THREE
86
+ })
87
+ end
88
+ end
89
+
90
+ context 'when coercing from enum' do
91
+ subject { Test::StatusType::PENDING }
92
+ it { should eq(0) }
93
+ end
94
+
95
+ context 'when coercing from integer' do
96
+ specify { 0.should eq(Test::StatusType::PENDING) }
97
+ end
98
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Protobuf::EnumValue do
4
+
5
+ subject { Test::EnumTestType::ONE }
6
+ its(:class) { should eq(Fixnum) }
7
+ its(:parent_class) { should eq(Test::EnumTestType) }
8
+ its(:name) { should eq(:ONE) }
9
+ its(:value) { should eq(1) }
10
+ its(:to_hash_value) { should eq(1) }
11
+ its(:to_s) { should eq("1") }
12
+ its(:inspect) { should eq('#<Protobuf::EnumValue Test::EnumTestType::ONE=1>') }
13
+ specify { subject.to_s(:name).should eq("ONE") }
14
+
15
+ end
@@ -0,0 +1,131 @@
1
+ require 'protobuf/logger'
2
+ require 'stringio'
3
+
4
+ describe Protobuf::Logger do
5
+
6
+ subject { Protobuf::Logger }
7
+
8
+ before(:each) do
9
+ Protobuf::Logger.reset_device!
10
+ Protobuf::Logger.file = '/dev/null'
11
+ Protobuf::Logger.level = ::Logger::INFO
12
+ end
13
+
14
+ describe '.instance' do
15
+
16
+ it 'doesn\'t create a logger if the file was not set' do
17
+ subject.file = nil
18
+ subject.instance.should be_nil
19
+ end
20
+
21
+ it 'doesn\'t create a logger if the level was not set' do
22
+ subject.level = nil
23
+ subject.instance.should be_nil
24
+ end
25
+
26
+ it 'gets a new instance of the logger when file and level are set' do
27
+ subject.file.should_not be_nil
28
+ subject.level.should_not be_nil
29
+ subject.instance.should_not be_nil
30
+ end
31
+
32
+ it 'keeps the same object from multiple calls to instance' do
33
+ subject.instance === subject.instance
34
+ end
35
+
36
+ end
37
+
38
+ describe '.configure' do
39
+ before(:each) { subject.reset_device! }
40
+ it 'sets the file and level in one call' do
41
+ subject.file.should_not be
42
+ subject.level.should_not be
43
+ subject.instance.should_not be
44
+ subject.configure :file => 'myfile.log', :level => ::Logger::WARN
45
+ subject.file.should == 'myfile.log'
46
+ subject.level.should == ::Logger::WARN
47
+ subject.instance.level.should == ::Logger::WARN
48
+ end
49
+
50
+ end
51
+
52
+ describe '.reset_device!' do
53
+
54
+ it 'resets the logger instance, file, and level' do
55
+ subject.instance.should be
56
+ subject.file.should be
57
+ subject.level.should be
58
+ subject.reset_device!
59
+ subject.instance.should_not be
60
+ subject.file.should_not be
61
+ subject.level.should_not be
62
+ end
63
+
64
+ end
65
+
66
+ context 'when logging' do
67
+
68
+ it 'doesn\'t raise errors when log instance is nil' do
69
+ subject.reset_device!
70
+ subject.instance.should be_nil
71
+ expect {
72
+ subject.debug 'No errors here'
73
+ subject.info 'No errors here'
74
+ subject.warn 'No errors here'
75
+ subject.error 'No errors here'
76
+ subject.fatal 'No errors here'
77
+ subject.add 'No errors here'
78
+ subject.log 'No errors here'
79
+ }.to_not raise_error
80
+ end
81
+
82
+ it 'logs correctly when instance is valid' do
83
+ subject.instance.should_not be_nil
84
+ subject.instance.should_receive(:info).with('Should log great')
85
+ subject.info 'Should log great'
86
+ end
87
+
88
+ end
89
+
90
+ describe Protobuf::Logger::LogMethods do
91
+
92
+ context 'when included in another class' do
93
+
94
+ before(:all) do
95
+ class MyTestClass
96
+ include Protobuf::Logger::LogMethods
97
+ end
98
+ end
99
+
100
+ subject { MyTestClass.new }
101
+
102
+ it { should respond_to(:log_debug) }
103
+ it { should respond_to(:log_info) }
104
+ it { should respond_to(:log_warn) }
105
+ it { should respond_to(:log_error) }
106
+ it { should respond_to(:log_fatal) }
107
+ it { should respond_to(:log_add) }
108
+ it { should respond_to(:log_log) }
109
+
110
+ context '#log_exception' do
111
+ it 'logs the exception message as an error and backtrace as debug' do
112
+ subject.should_receive(:log_error).twice
113
+ subject.should_receive(:log_debug)
114
+ subject.log_exception(RuntimeError.new('this is an exception'))
115
+ end
116
+ end
117
+
118
+ its(:log_signature) { should eq "[MyTestClass]" }
119
+ describe '#sign_message' do
120
+ specify { subject.sign_message("this is a test").should eq "[MyTestClass] this is a test" }
121
+ specify { subject.class.sign_message("this is a test").should eq "[MyTestClass] this is a test" }
122
+ end
123
+
124
+ it 'passes all embedded log calls to Logger instance' do
125
+ Protobuf::Logger.instance.should_receive(:debug).with('[MyTestClass] log this')
126
+ subject.log_debug('log this')
127
+ end
128
+
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ class EncoderTest
4
+ extend ::Protobuf::Encoder
5
+ end
6
+
7
+ describe Protobuf::Encoder do
8
+ describe '#encode' do
9
+ context "when there's no value for a required field" do
10
+ let(:message) { ::Test::Resource.new }
11
+ let(:stream) { StringIO.new }
12
+ it "raises a 'message not initialized' error" do
13
+ expect {
14
+ EncoderTest.__send__(:encode, stream, message)
15
+ }.to raise_error(Protobuf::NotInitializedError, /message.*not initialized/i)
16
+ end
17
+ end
18
+ end
19
+ end