protobuf 3.7.0.pre2 → 3.7.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -1
  3. data/.rubocop_todo.yml +7 -1
  4. data/.travis.yml +8 -1
  5. data/CHANGES.md +25 -1
  6. data/bin/protoc-gen-ruby +2 -2
  7. data/lib/protobuf/cli.rb +29 -17
  8. data/lib/protobuf/code_generator.rb +49 -1
  9. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +9 -1
  10. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +14 -1
  11. data/lib/protobuf/encoder.rb +2 -2
  12. data/lib/protobuf/enum.rb +3 -3
  13. data/lib/protobuf/field/base_field.rb +27 -19
  14. data/lib/protobuf/field/bool_field.rb +10 -8
  15. data/lib/protobuf/field/bytes_field.rb +14 -6
  16. data/lib/protobuf/field/float_field.rb +2 -0
  17. data/lib/protobuf/field/string_field.rb +10 -0
  18. data/lib/protobuf/field/varint_field.rb +12 -2
  19. data/lib/protobuf/generators/base.rb +29 -14
  20. data/lib/protobuf/generators/enum_generator.rb +4 -7
  21. data/lib/protobuf/generators/field_generator.rb +17 -4
  22. data/lib/protobuf/generators/file_generator.rb +121 -10
  23. data/lib/protobuf/generators/group_generator.rb +9 -3
  24. data/lib/protobuf/generators/message_generator.rb +8 -2
  25. data/lib/protobuf/generators/option_generator.rb +17 -0
  26. data/lib/protobuf/generators/printable.rb +2 -2
  27. data/lib/protobuf/generators/service_generator.rb +27 -3
  28. data/lib/protobuf/lifecycle.rb +1 -1
  29. data/lib/protobuf/message/fields.rb +13 -15
  30. data/lib/protobuf/message/serialization.rb +9 -9
  31. data/lib/protobuf/message.rb +23 -29
  32. data/lib/protobuf/optionable.rb +10 -10
  33. data/lib/protobuf/rpc/buffer.rb +7 -6
  34. data/lib/protobuf/rpc/client.rb +2 -30
  35. data/lib/protobuf/rpc/connectors/base.rb +168 -6
  36. data/lib/protobuf/rpc/connectors/ping.rb +2 -2
  37. data/lib/protobuf/rpc/connectors/socket.rb +6 -1
  38. data/lib/protobuf/rpc/connectors/zmq.rb +1 -2
  39. data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -1
  40. data/lib/protobuf/rpc/error.rb +2 -2
  41. data/lib/protobuf/rpc/middleware/exception_handler.rb +4 -0
  42. data/lib/protobuf/rpc/middleware/logger.rb +4 -0
  43. data/lib/protobuf/rpc/middleware/request_decoder.rb +11 -16
  44. data/lib/protobuf/rpc/middleware/response_encoder.rb +18 -23
  45. data/lib/protobuf/rpc/rpc.pb.rb +2 -1
  46. data/lib/protobuf/rpc/rpc_method.rb +16 -0
  47. data/lib/protobuf/rpc/servers/socket/server.rb +4 -4
  48. data/lib/protobuf/rpc/servers/socket_runner.rb +8 -0
  49. data/lib/protobuf/rpc/servers/zmq/broker.rb +7 -6
  50. data/lib/protobuf/rpc/servers/zmq/server.rb +8 -7
  51. data/lib/protobuf/rpc/servers/zmq/util.rb +6 -6
  52. data/lib/protobuf/rpc/servers/zmq/worker.rb +7 -6
  53. data/lib/protobuf/rpc/servers/zmq_runner.rb +8 -0
  54. data/lib/protobuf/rpc/service.rb +6 -15
  55. data/lib/protobuf/rpc/service_directory.rb +1 -1
  56. data/lib/protobuf/rpc/service_dispatcher.rb +5 -6
  57. data/lib/protobuf/rpc/service_filters.rb +8 -30
  58. data/lib/protobuf/socket.rb +2 -2
  59. data/lib/protobuf/version.rb +1 -1
  60. data/lib/protobuf/zmq.rb +2 -2
  61. data/lib/protobuf.rb +12 -27
  62. data/protobuf.gemspec +5 -3
  63. data/spec/benchmark/tasks.rb +1 -0
  64. data/spec/functional/code_generator_spec.rb +38 -0
  65. data/spec/lib/protobuf/cli_spec.rb +19 -10
  66. data/spec/lib/protobuf/code_generator_spec.rb +28 -0
  67. data/spec/lib/protobuf/enum_spec.rb +6 -2
  68. data/spec/lib/protobuf/field/bool_field_spec.rb +4 -0
  69. data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
  70. data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
  71. data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
  72. data/spec/lib/protobuf/field/float_field_spec.rb +5 -1
  73. data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
  74. data/spec/lib/protobuf/field/message_field_spec.rb +53 -0
  75. data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
  76. data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
  77. data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
  78. data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
  79. data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
  80. data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
  81. data/spec/lib/protobuf/generators/base_spec.rb +69 -1
  82. data/spec/lib/protobuf/generators/enum_generator_spec.rb +1 -1
  83. data/spec/lib/protobuf/generators/field_generator_spec.rb +58 -0
  84. data/spec/lib/protobuf/generators/file_generator_spec.rb +47 -0
  85. data/spec/lib/protobuf/generators/service_generator_spec.rb +58 -14
  86. data/spec/lib/protobuf/message_spec.rb +2 -2
  87. data/spec/lib/protobuf/optionable_spec.rb +96 -0
  88. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +151 -0
  89. data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +3 -3
  90. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +0 -2
  91. data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +2 -2
  92. data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +4 -4
  93. data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +2 -2
  94. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +1 -18
  95. data/spec/lib/protobuf/rpc/service_filters_spec.rb +2 -2
  96. data/spec/lib/protobuf/varint_spec.rb +1 -1
  97. data/spec/lib/protobuf_spec.rb +13 -16
  98. data/spec/support/packed_field.rb +3 -2
  99. data/spec/support/protos/enum.pb.rb +2 -1
  100. data/spec/support/protos/enum.proto +1 -0
  101. data/spec/support/protos/google_unittest.pb.rb +69 -58
  102. data/spec/support/protos/google_unittest_custom_options.bin +0 -0
  103. data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
  104. data/spec/support/protos/google_unittest_custom_options.proto +424 -0
  105. data/spec/support/protos/google_unittest_import.pb.rb +8 -0
  106. data/spec/support/protos/google_unittest_import_public.pb.rb +6 -0
  107. data/spec/support/protos/resource.pb.rb +54 -2
  108. data/spec/support/protos/resource.proto +42 -2
  109. data/spec/support/server.rb +1 -1
  110. metadata +39 -16
  111. data/lib/protobuf/rpc/connector.rb +0 -19
  112. data/lib/protobuf/rpc/connectors/common.rb +0 -176
  113. data/spec/lib/protobuf/rpc/connector_spec.rb +0 -26
  114. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +0 -170
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0.pre2
4
+ version: 3.7.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Neilsen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-06-20 00:00:00.000000000 Z
14
+ date: 2017-03-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -87,16 +87,16 @@ dependencies:
87
87
  name: rake
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - ">="
90
+ - - "<"
91
91
  - !ruby/object:Gem::Version
92
- version: '0'
92
+ version: '11.0'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - "<"
98
98
  - !ruby/object:Gem::Version
99
- version: '0'
99
+ version: '11.0'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: rspec
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -117,14 +117,14 @@ dependencies:
117
117
  requirements:
118
118
  - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: 0.35.0
120
+ version: 0.38.0
121
121
  type: :development
122
122
  prerelease: false
123
123
  version_requirements: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - "~>"
126
126
  - !ruby/object:Gem::Version
127
- version: 0.35.0
127
+ version: 0.38.0
128
128
  - !ruby/object:Gem::Dependency
129
129
  name: parser
130
130
  requirement: !ruby/object:Gem::Requirement
@@ -304,6 +304,7 @@ files:
304
304
  - lib/protobuf/generators/file_generator.rb
305
305
  - lib/protobuf/generators/group_generator.rb
306
306
  - lib/protobuf/generators/message_generator.rb
307
+ - lib/protobuf/generators/option_generator.rb
307
308
  - lib/protobuf/generators/printable.rb
308
309
  - lib/protobuf/generators/service_generator.rb
309
310
  - lib/protobuf/lifecycle.rb
@@ -314,9 +315,7 @@ files:
314
315
  - lib/protobuf/optionable.rb
315
316
  - lib/protobuf/rpc/buffer.rb
316
317
  - lib/protobuf/rpc/client.rb
317
- - lib/protobuf/rpc/connector.rb
318
318
  - lib/protobuf/rpc/connectors/base.rb
319
- - lib/protobuf/rpc/connectors/common.rb
320
319
  - lib/protobuf/rpc/connectors/ping.rb
321
320
  - lib/protobuf/rpc/connectors/socket.rb
322
321
  - lib/protobuf/rpc/connectors/zmq.rb
@@ -332,6 +331,7 @@ files:
332
331
  - lib/protobuf/rpc/middleware/response_encoder.rb
333
332
  - lib/protobuf/rpc/middleware/runner.rb
334
333
  - lib/protobuf/rpc/rpc.pb.rb
334
+ - lib/protobuf/rpc/rpc_method.rb
335
335
  - lib/protobuf/rpc/server.rb
336
336
  - lib/protobuf/rpc/servers/socket/server.rb
337
337
  - lib/protobuf/rpc/servers/socket/worker.rb
@@ -364,18 +364,29 @@ files:
364
364
  - spec/encoding/all_types_spec.rb
365
365
  - spec/encoding/extreme_values_spec.rb
366
366
  - spec/functional/class_inheritance_spec.rb
367
+ - spec/functional/code_generator_spec.rb
367
368
  - spec/functional/socket_server_spec.rb
368
369
  - spec/functional/zmq_server_spec.rb
369
370
  - spec/lib/protobuf/cli_spec.rb
370
371
  - spec/lib/protobuf/code_generator_spec.rb
371
372
  - spec/lib/protobuf/enum_spec.rb
372
373
  - spec/lib/protobuf/field/bool_field_spec.rb
374
+ - spec/lib/protobuf/field/double_field_spec.rb
373
375
  - spec/lib/protobuf/field/enum_field_spec.rb
374
376
  - spec/lib/protobuf/field/field_array_spec.rb
377
+ - spec/lib/protobuf/field/fixed32_field_spec.rb
378
+ - spec/lib/protobuf/field/fixed64_field_spec.rb
375
379
  - spec/lib/protobuf/field/float_field_spec.rb
376
380
  - spec/lib/protobuf/field/int32_field_spec.rb
381
+ - spec/lib/protobuf/field/int64_field_spec.rb
377
382
  - spec/lib/protobuf/field/message_field_spec.rb
383
+ - spec/lib/protobuf/field/sfixed32_field_spec.rb
384
+ - spec/lib/protobuf/field/sfixed64_field_spec.rb
385
+ - spec/lib/protobuf/field/sint32_field_spec.rb
386
+ - spec/lib/protobuf/field/sint64_field_spec.rb
378
387
  - spec/lib/protobuf/field/string_field_spec.rb
388
+ - spec/lib/protobuf/field/uint32_field_spec.rb
389
+ - spec/lib/protobuf/field/uint64_field_spec.rb
379
390
  - spec/lib/protobuf/field_spec.rb
380
391
  - spec/lib/protobuf/generators/base_spec.rb
381
392
  - spec/lib/protobuf/generators/enum_generator_spec.rb
@@ -388,9 +399,7 @@ files:
388
399
  - spec/lib/protobuf/message_spec.rb
389
400
  - spec/lib/protobuf/optionable_spec.rb
390
401
  - spec/lib/protobuf/rpc/client_spec.rb
391
- - spec/lib/protobuf/rpc/connector_spec.rb
392
402
  - spec/lib/protobuf/rpc/connectors/base_spec.rb
393
- - spec/lib/protobuf/rpc/connectors/common_spec.rb
394
403
  - spec/lib/protobuf/rpc/connectors/ping_spec.rb
395
404
  - spec/lib/protobuf/rpc/connectors/socket_spec.rb
396
405
  - spec/lib/protobuf/rpc/connectors/zmq_spec.rb
@@ -420,6 +429,9 @@ files:
420
429
  - spec/support/protos/google_unittest.bin
421
430
  - spec/support/protos/google_unittest.pb.rb
422
431
  - spec/support/protos/google_unittest.proto
432
+ - spec/support/protos/google_unittest_custom_options.bin
433
+ - spec/support/protos/google_unittest_custom_options.pb.rb
434
+ - spec/support/protos/google_unittest_custom_options.proto
423
435
  - spec/support/protos/google_unittest_import.pb.rb
424
436
  - spec/support/protos/google_unittest_import.proto
425
437
  - spec/support/protos/google_unittest_import_public.pb.rb
@@ -451,7 +463,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
451
463
  version: 1.3.1
452
464
  requirements: []
453
465
  rubyforge_project:
454
- rubygems_version: 2.4.5
466
+ rubygems_version: 2.5.2
455
467
  signing_key:
456
468
  specification_version: 4
457
469
  summary: Google Protocol Buffers serialization and RPC implementation for Ruby.
@@ -461,18 +473,29 @@ test_files:
461
473
  - spec/encoding/all_types_spec.rb
462
474
  - spec/encoding/extreme_values_spec.rb
463
475
  - spec/functional/class_inheritance_spec.rb
476
+ - spec/functional/code_generator_spec.rb
464
477
  - spec/functional/socket_server_spec.rb
465
478
  - spec/functional/zmq_server_spec.rb
466
479
  - spec/lib/protobuf/cli_spec.rb
467
480
  - spec/lib/protobuf/code_generator_spec.rb
468
481
  - spec/lib/protobuf/enum_spec.rb
469
482
  - spec/lib/protobuf/field/bool_field_spec.rb
483
+ - spec/lib/protobuf/field/double_field_spec.rb
470
484
  - spec/lib/protobuf/field/enum_field_spec.rb
471
485
  - spec/lib/protobuf/field/field_array_spec.rb
486
+ - spec/lib/protobuf/field/fixed32_field_spec.rb
487
+ - spec/lib/protobuf/field/fixed64_field_spec.rb
472
488
  - spec/lib/protobuf/field/float_field_spec.rb
473
489
  - spec/lib/protobuf/field/int32_field_spec.rb
490
+ - spec/lib/protobuf/field/int64_field_spec.rb
474
491
  - spec/lib/protobuf/field/message_field_spec.rb
492
+ - spec/lib/protobuf/field/sfixed32_field_spec.rb
493
+ - spec/lib/protobuf/field/sfixed64_field_spec.rb
494
+ - spec/lib/protobuf/field/sint32_field_spec.rb
495
+ - spec/lib/protobuf/field/sint64_field_spec.rb
475
496
  - spec/lib/protobuf/field/string_field_spec.rb
497
+ - spec/lib/protobuf/field/uint32_field_spec.rb
498
+ - spec/lib/protobuf/field/uint64_field_spec.rb
476
499
  - spec/lib/protobuf/field_spec.rb
477
500
  - spec/lib/protobuf/generators/base_spec.rb
478
501
  - spec/lib/protobuf/generators/enum_generator_spec.rb
@@ -485,9 +508,7 @@ test_files:
485
508
  - spec/lib/protobuf/message_spec.rb
486
509
  - spec/lib/protobuf/optionable_spec.rb
487
510
  - spec/lib/protobuf/rpc/client_spec.rb
488
- - spec/lib/protobuf/rpc/connector_spec.rb
489
511
  - spec/lib/protobuf/rpc/connectors/base_spec.rb
490
- - spec/lib/protobuf/rpc/connectors/common_spec.rb
491
512
  - spec/lib/protobuf/rpc/connectors/ping_spec.rb
492
513
  - spec/lib/protobuf/rpc/connectors/socket_spec.rb
493
514
  - spec/lib/protobuf/rpc/connectors/zmq_spec.rb
@@ -517,6 +538,9 @@ test_files:
517
538
  - spec/support/protos/google_unittest.bin
518
539
  - spec/support/protos/google_unittest.pb.rb
519
540
  - spec/support/protos/google_unittest.proto
541
+ - spec/support/protos/google_unittest_custom_options.bin
542
+ - spec/support/protos/google_unittest_custom_options.pb.rb
543
+ - spec/support/protos/google_unittest_custom_options.proto
520
544
  - spec/support/protos/google_unittest_import.pb.rb
521
545
  - spec/support/protos/google_unittest_import.proto
522
546
  - spec/support/protos/google_unittest_import_public.pb.rb
@@ -528,4 +552,3 @@ test_files:
528
552
  - spec/support/resource_service.rb
529
553
  - spec/support/server.rb
530
554
  - spec/support/test_app_file.rb
531
- has_rdoc:
@@ -1,19 +0,0 @@
1
- require 'protobuf'
2
-
3
- module Protobuf
4
- module Rpc
5
- class Connector
6
-
7
- # Returns a connector class for the pre-defined connector_type.
8
- def self.connector_for_client
9
- case ::Protobuf.connector_type
10
- when :zmq then
11
- ::Protobuf::Rpc::Connectors::Zmq
12
- else
13
- ::Protobuf::Rpc::Connectors::Socket
14
- end
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,176 +0,0 @@
1
- require 'protobuf'
2
-
3
- module Protobuf
4
- module Rpc
5
- module Connectors
6
- module Common
7
-
8
- attr_reader :error
9
-
10
- def any_callbacks?
11
- [@complete_cb, @failure_cb, @success_cb].any?
12
- end
13
-
14
- def request_caller
15
- @options[:client_host] || ::Protobuf.client_host
16
- end
17
-
18
- def complete
19
- @stats.stop
20
- logger.info { @stats.to_s }
21
- logger.debug { sign_message('Response proceessing complete') }
22
- @complete_cb.call(self) unless @complete_cb.nil?
23
- rescue => e
24
- logger.error { sign_message('Complete callback error encountered') }
25
- log_exception(e)
26
- raise
27
- end
28
-
29
- def data_callback(data)
30
- logger.debug { sign_message('Using data_callback') }
31
- @used_data_callback = true
32
- @data = data
33
- end
34
-
35
- # All failures should be routed through this method.
36
- #
37
- # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason)
38
- # @param [String] message The error message
39
- def failure(code, message)
40
- @error = ClientError.new
41
- @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code)
42
- @error.message = message
43
- logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") }
44
-
45
- @failure_cb.call(@error) unless @failure_cb.nil?
46
- rescue => e
47
- logger.error { sign_message("Failure callback error encountered") }
48
- log_exception(e)
49
- raise
50
- ensure
51
- complete
52
- end
53
-
54
- def initialize_stats
55
- @stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
56
- @stats.server = [@options[:port], @options[:host]]
57
- @stats.service = @options[:service].name
58
- @stats.method_name = @options[:method].to_s
59
- rescue => ex
60
- log_exception(ex)
61
- failure(:RPC_ERROR, "Invalid stats configuration. #{ex.message}")
62
- end
63
-
64
- def log_signature
65
- @_log_signature ||= "[client-#{self.class}]"
66
- end
67
-
68
- def parse_response
69
- # Close up the connection as we no longer need it
70
- close_connection
71
-
72
- logger.debug { sign_message("Parsing response from server (connection closed)") }
73
-
74
- # Parse out the raw response
75
- @stats.response_size = @response_data.size unless @response_data.nil?
76
- response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data)
77
-
78
- # Determine success or failure based on parsed data
79
- if response_wrapper.field?(:error_reason)
80
- logger.debug { sign_message("Error response parsed") }
81
-
82
- # fail the call if we already know the client is failed
83
- # (don't try to parse out the response payload)
84
- failure(response_wrapper.error_reason, response_wrapper.error)
85
- else
86
- logger.debug { sign_message("Successful response parsed") }
87
-
88
- # Ensure client_response is an instance
89
- parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s)
90
-
91
- if parsed.nil? && !response_wrapper.field?(:error_reason)
92
- failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server')
93
- else
94
- verify_callbacks
95
- succeed(parsed)
96
- return @data if @used_data_callback
97
- end
98
- end
99
- end
100
-
101
- def post_init
102
- send_data unless error?
103
- rescue => e
104
- failure(:RPC_ERROR, "Connection error: #{e.message}")
105
- end
106
-
107
- def request_bytes
108
- validate_request_type!
109
- fields = { :service_name => @options[:service].name,
110
- :method_name => @options[:method].to_s,
111
- :request_proto => @options[:request],
112
- :caller => request_caller }
113
-
114
- return ::Protobuf::Socketrpc::Request.encode(fields)
115
- rescue => e
116
- failure(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}")
117
- end
118
-
119
- def setup_connection
120
- initialize_stats
121
- @request_data = request_bytes
122
- @stats.request_size = request_bytes.size
123
- end
124
-
125
- def succeed(response)
126
- logger.debug { sign_message("Server succeeded request (invoking on_success)") }
127
- @success_cb.call(response) unless @success_cb.nil?
128
- rescue => e
129
- logger.error { sign_message("Success callback error encountered") }
130
- log_exception(e)
131
- failure(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}")
132
- ensure
133
- complete
134
- end
135
-
136
- def timeout
137
- if options[:timeout]
138
- options[:timeout]
139
- else
140
- 300 # seconds
141
- end
142
- end
143
-
144
- # Wrap the given block in a timeout of the configured number of seconds.
145
- #
146
- def timeout_wrap(&block)
147
- ::Timeout.timeout(timeout, &block)
148
- rescue ::Timeout::Error
149
- failure(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond")
150
- end
151
-
152
- def validate_request_type!
153
- unless @options[:request].class == @options[:request_type]
154
- expected = @options[:request_type].name
155
- actual = @options[:request].class.name
156
- failure(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead")
157
- end
158
- end
159
-
160
- def verify_callbacks
161
- unless any_callbacks?
162
- logger.debug { sign_message("No callbacks set, using data_callback") }
163
- @success_cb = @failure_cb = method(:data_callback)
164
- end
165
- end
166
-
167
- def verify_options!
168
- # Verify the options that are necessary and merge them in
169
- [:service, :method, :host, :port].each do |opt|
170
- failure(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil?
171
- end
172
- end
173
- end
174
- end
175
- end
176
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'protobuf/socket'
3
- require 'protobuf/zmq'
4
-
5
- RSpec.describe ::Protobuf::Rpc::Connector do
6
-
7
- describe '.connector_for_client(true)' do
8
- subject { described_class.connector_for_client }
9
-
10
- context 'Protobuf.connector_type is socket' do
11
- before { ::Protobuf.connector_type = :socket }
12
- specify { expect(subject).to eq ::Protobuf::Rpc::Connectors::Socket }
13
- end
14
-
15
- context 'Protobuf.connector_type is not a known value' do
16
- before { allow(::Protobuf).to receive(:connector_type).and_return(:foo) }
17
- specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Socket) }
18
- end
19
-
20
- context 'Protobuf.connector_type is zmq' do
21
- before { ::Protobuf.connector_type = :zmq }
22
- specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Zmq) }
23
- end
24
- end
25
-
26
- end
@@ -1,170 +0,0 @@
1
- require 'spec_helper'
2
- require 'protobuf/rpc/service'
3
-
4
- RSpec.describe Protobuf::Rpc::Connectors::Common do
5
- let(:common_class) do
6
- Class.new(Protobuf::Rpc::Connectors::Base) do
7
- include Protobuf::Rpc::Connectors::Common
8
- attr_accessor :options
9
- attr_accessor :stats
10
- end
11
- end
12
-
13
- let(:subject_options) { {} }
14
-
15
- subject { @subject ||= common_class.new(subject_options) }
16
-
17
- context "API" do
18
- specify { expect(subject.respond_to?(:any_callbacks?)).to be true }
19
- specify { expect(subject.respond_to?(:request_caller)).to be true }
20
- specify { expect(subject.respond_to?(:data_callback)).to be true }
21
- specify { expect(subject.respond_to?(:error)).to be true }
22
- specify { expect(subject.respond_to?(:failure)).to be true }
23
- specify { expect(subject.respond_to?(:complete)).to be true }
24
- specify { expect(subject.respond_to?(:parse_response)).to be true }
25
- specify { expect(subject.respond_to?(:verify_options!)).to be true }
26
- specify { expect(subject.respond_to?(:verify_callbacks)).to be true }
27
- end
28
-
29
- describe "#any_callbacks?" do
30
-
31
- [:@complete_cb, :@success_cb, :@failure_cb].each do |cb|
32
- it "returns true if #{cb} is provided" do
33
- subject.instance_variable_set(cb, "something")
34
- expect(subject.any_callbacks?).to be true
35
- end
36
- end
37
-
38
- it "returns false when all callbacks are not provided" do
39
- subject.instance_variable_set(:@complete_cb, nil)
40
- subject.instance_variable_set(:@success_cb, nil)
41
- subject.instance_variable_set(:@failure_cb, nil)
42
-
43
- expect(subject.any_callbacks?).to be false
44
- end
45
-
46
- end
47
-
48
- describe '#request_caller' do
49
- specify { expect(subject.request_caller).to eq ::Protobuf.client_host }
50
-
51
- context 'when "client_host" option is given to initializer' do
52
- let(:hostname) { 'myhost.myserver.com' }
53
- let(:subject_options) { { :client_host => hostname } }
54
-
55
- specify { expect(subject.request_caller).to_not eq ::Protobuf.client_host }
56
- specify { expect(subject.request_caller).to eq hostname }
57
- end
58
- end
59
-
60
- describe "#data_callback" do
61
- it "changes state to use the data callback" do
62
- subject.data_callback("data")
63
- expect(subject.instance_variable_get(:@used_data_callback)).to be true
64
- end
65
-
66
- it "sets the data var when using the data_callback" do
67
- subject.data_callback("data")
68
- expect(subject.instance_variable_get(:@data)).to eq("data")
69
- end
70
- end
71
-
72
- describe '#request_bytes' do
73
- let(:service) { Test::ResourceService }
74
- let(:method) { :find }
75
- let(:request) { '' }
76
- let(:client_host) { 'myhost.myservice.com' }
77
- let(:subject_options) do
78
- {
79
- :service => service,
80
- :method => method,
81
- :request => request,
82
- :client_host => client_host,
83
- }
84
- end
85
-
86
- let(:expected) do
87
- ::Protobuf::Socketrpc::Request.new(
88
- :service_name => service.name,
89
- :method_name => 'find',
90
- :request_proto => '',
91
- :caller => client_host,
92
- )
93
- end
94
-
95
- before { allow(subject).to receive(:validate_request_type!).and_return(true) }
96
- before { expect(subject).not_to receive(:failure) }
97
-
98
- specify { expect(subject.request_bytes).to eq expected.encode }
99
- end
100
-
101
- describe "#verify_callbacks" do
102
-
103
- it "sets @failure_cb to #data_callback when no callbacks are defined" do
104
- subject.verify_callbacks
105
- expect(subject.instance_variable_get(:@failure_cb)).to eq(subject.method(:data_callback))
106
- end
107
-
108
- it "sets @success_cb to #data_callback when no callbacks are defined" do
109
- subject.verify_callbacks
110
- expect(subject.instance_variable_get(:@success_cb)).to eq(subject.method(:data_callback))
111
- end
112
-
113
- it "doesn't set @failure_cb when already defined" do
114
- set_cb = -> { true }
115
- subject.instance_variable_set(:@failure_cb, set_cb)
116
- subject.verify_callbacks
117
- expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb)
118
- expect(subject.instance_variable_get(:@failure_cb)).to_not eq(subject.method(:data_callback))
119
- end
120
-
121
- it "doesn't set @success_cb when already defined" do
122
- set_cb = -> { true }
123
- subject.instance_variable_set(:@success_cb, set_cb)
124
- subject.verify_callbacks
125
- expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb)
126
- expect(subject.instance_variable_get(:@success_cb)).to_not eq(subject.method(:data_callback))
127
- end
128
-
129
- end
130
-
131
- shared_examples "a ConnectorDisposition" do |meth, cb, *args|
132
-
133
- it "calls #complete before exit" do
134
- subject.stats = double("Object", :stop => true)
135
-
136
- expect(subject).to receive(:complete)
137
- subject.method(meth).call(*args)
138
- end
139
-
140
- it "calls the #{cb} callback when provided" do
141
- stats = double("Object")
142
- allow(stats).to receive(:stop).and_return(true)
143
- subject.stats = stats
144
- some_cb = double("Object")
145
-
146
- subject.instance_variable_set("@#{cb}", some_cb)
147
- expect(some_cb).to receive(:call).and_return(true)
148
- subject.method(meth).call(*args)
149
- end
150
-
151
- it "calls the complete callback when provided" do
152
- stats = double("Object")
153
- allow(stats).to receive(:stop).and_return(true)
154
- subject.stats = stats
155
- comp_cb = double("Object")
156
-
157
- subject.instance_variable_set(:@complete_cb, comp_cb)
158
- expect(comp_cb).to receive(:call).and_return(true)
159
- subject.method(meth).call(*args)
160
- end
161
-
162
- end
163
-
164
- it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message")
165
- it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message")
166
- it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response")
167
- it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response")
168
- it_behaves_like("a ConnectorDisposition", :complete, "complete_cb")
169
-
170
- end