prepor-protobuf 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rubocop.yml +51 -0
- data/.rubocop_todo.yml +89 -0
- data/.travis.yml +25 -0
- data/.yardopts +5 -0
- data/CHANGES.md +256 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +64 -0
- data/bin/protoc-gen-ruby +16 -0
- data/bin/rpc_server +5 -0
- data/install-protobuf.sh +28 -0
- data/lib/protobuf.rb +100 -0
- data/lib/protobuf/cli.rb +242 -0
- data/lib/protobuf/code_generator.rb +44 -0
- data/lib/protobuf/decoder.rb +73 -0
- data/lib/protobuf/deprecation.rb +112 -0
- data/lib/protobuf/descriptors.rb +3 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +48 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +251 -0
- data/lib/protobuf/encoder.rb +67 -0
- data/lib/protobuf/enum.rb +303 -0
- data/lib/protobuf/exceptions.rb +9 -0
- data/lib/protobuf/field.rb +74 -0
- data/lib/protobuf/field/base_field.rb +267 -0
- data/lib/protobuf/field/bool_field.rb +59 -0
- data/lib/protobuf/field/bytes_field.rb +82 -0
- data/lib/protobuf/field/double_field.rb +25 -0
- data/lib/protobuf/field/enum_field.rb +68 -0
- data/lib/protobuf/field/field_array.rb +87 -0
- data/lib/protobuf/field/fixed32_field.rb +25 -0
- data/lib/protobuf/field/fixed64_field.rb +28 -0
- data/lib/protobuf/field/float_field.rb +41 -0
- data/lib/protobuf/field/int32_field.rb +21 -0
- data/lib/protobuf/field/int64_field.rb +21 -0
- data/lib/protobuf/field/integer_field.rb +23 -0
- data/lib/protobuf/field/message_field.rb +65 -0
- data/lib/protobuf/field/sfixed32_field.rb +27 -0
- data/lib/protobuf/field/sfixed64_field.rb +28 -0
- data/lib/protobuf/field/signed_integer_field.rb +29 -0
- data/lib/protobuf/field/sint32_field.rb +21 -0
- data/lib/protobuf/field/sint64_field.rb +21 -0
- data/lib/protobuf/field/string_field.rb +34 -0
- data/lib/protobuf/field/uint32_field.rb +21 -0
- data/lib/protobuf/field/uint64_field.rb +21 -0
- data/lib/protobuf/field/varint_field.rb +73 -0
- data/lib/protobuf/generators/base.rb +70 -0
- data/lib/protobuf/generators/enum_generator.rb +41 -0
- data/lib/protobuf/generators/extension_generator.rb +27 -0
- data/lib/protobuf/generators/field_generator.rb +131 -0
- data/lib/protobuf/generators/file_generator.rb +135 -0
- data/lib/protobuf/generators/group_generator.rb +112 -0
- data/lib/protobuf/generators/message_generator.rb +98 -0
- data/lib/protobuf/generators/printable.rb +160 -0
- data/lib/protobuf/generators/service_generator.rb +26 -0
- data/lib/protobuf/lifecycle.rb +33 -0
- data/lib/protobuf/logging.rb +39 -0
- data/lib/protobuf/message.rb +193 -0
- data/lib/protobuf/message/fields.rb +133 -0
- data/lib/protobuf/message/serialization.rb +89 -0
- data/lib/protobuf/optionable.rb +23 -0
- data/lib/protobuf/rpc/buffer.rb +77 -0
- data/lib/protobuf/rpc/client.rb +168 -0
- data/lib/protobuf/rpc/connector.rb +19 -0
- data/lib/protobuf/rpc/connectors/base.rb +55 -0
- data/lib/protobuf/rpc/connectors/common.rb +176 -0
- data/lib/protobuf/rpc/connectors/socket.rb +73 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +322 -0
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +49 -0
- data/lib/protobuf/rpc/env.rb +58 -0
- data/lib/protobuf/rpc/error.rb +28 -0
- data/lib/protobuf/rpc/error/client_error.rb +31 -0
- data/lib/protobuf/rpc/error/server_error.rb +43 -0
- data/lib/protobuf/rpc/middleware.rb +25 -0
- data/lib/protobuf/rpc/middleware/exception_handler.rb +36 -0
- data/lib/protobuf/rpc/middleware/logger.rb +91 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +88 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/rpc.pb.rb +55 -0
- data/lib/protobuf/rpc/server.rb +39 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +123 -0
- data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
- data/lib/protobuf/rpc/servers/socket_runner.rb +40 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +193 -0
- data/lib/protobuf/rpc/servers/zmq/server.rb +320 -0
- data/lib/protobuf/rpc/servers/zmq/util.rb +48 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +104 -0
- data/lib/protobuf/rpc/servers/zmq_runner.rb +62 -0
- data/lib/protobuf/rpc/service.rb +179 -0
- data/lib/protobuf/rpc/service_directory.rb +253 -0
- data/lib/protobuf/rpc/service_dispatcher.rb +46 -0
- data/lib/protobuf/rpc/service_filters.rb +272 -0
- data/lib/protobuf/rpc/stat.rb +97 -0
- data/lib/protobuf/socket.rb +21 -0
- data/lib/protobuf/tasks.rb +1 -0
- data/lib/protobuf/tasks/compile.rake +61 -0
- data/lib/protobuf/version.rb +3 -0
- data/lib/protobuf/wire_type.rb +10 -0
- data/lib/protobuf/zmq.rb +21 -0
- data/proto/dynamic_discovery.proto +44 -0
- data/proto/google/protobuf/compiler/plugin.proto +147 -0
- data/proto/google/protobuf/descriptor.proto +620 -0
- data/proto/rpc.proto +62 -0
- data/protobuf.gemspec +51 -0
- data/spec/benchmark/tasks.rb +139 -0
- data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
- data/spec/data/data.bin +3 -0
- data/spec/data/types.bin +0 -0
- data/spec/encoding/all_types_spec.rb +105 -0
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/class_inheritance_spec.rb +52 -0
- data/spec/functional/socket_server_spec.rb +59 -0
- data/spec/functional/zmq_server_spec.rb +105 -0
- data/spec/lib/protobuf/cli_spec.rb +273 -0
- data/spec/lib/protobuf/code_generator_spec.rb +60 -0
- data/spec/lib/protobuf/enum_spec.rb +265 -0
- data/spec/lib/protobuf/field/bool_field_spec.rb +51 -0
- data/spec/lib/protobuf/field/field_array_spec.rb +69 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +55 -0
- data/spec/lib/protobuf/field/int32_field_spec.rb +89 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +45 -0
- data/spec/lib/protobuf/field_spec.rb +191 -0
- data/spec/lib/protobuf/generators/base_spec.rb +84 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +73 -0
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +42 -0
- data/spec/lib/protobuf/generators/field_generator_spec.rb +102 -0
- data/spec/lib/protobuf/generators/file_generator_spec.rb +32 -0
- data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
- data/spec/lib/protobuf/generators/service_generator_spec.rb +46 -0
- data/spec/lib/protobuf/lifecycle_spec.rb +94 -0
- data/spec/lib/protobuf/message_spec.rb +526 -0
- data/spec/lib/protobuf/optionable_spec.rb +46 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
- data/spec/lib/protobuf/rpc/connector_spec.rb +26 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +170 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +36 -0
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +117 -0
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +75 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +43 -0
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +293 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +52 -0
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +517 -0
- data/spec/lib/protobuf/rpc/service_spec.rb +162 -0
- data/spec/lib/protobuf/rpc/stat_spec.rb +68 -0
- data/spec/lib/protobuf_spec.rb +98 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/all.rb +6 -0
- data/spec/support/packed_field.rb +22 -0
- data/spec/support/server.rb +64 -0
- data/spec/support/test/all_types.data.bin +0 -0
- data/spec/support/test/all_types.data.txt +119 -0
- data/spec/support/test/defaults.pb.rb +27 -0
- data/spec/support/test/defaults.proto +9 -0
- data/spec/support/test/enum.pb.rb +55 -0
- data/spec/support/test/enum.proto +34 -0
- data/spec/support/test/extended.pb.rb +18 -0
- data/spec/support/test/extended.proto +10 -0
- data/spec/support/test/extreme_values.data.bin +0 -0
- data/spec/support/test/google_unittest.pb.rb +537 -0
- data/spec/support/test/google_unittest.proto +713 -0
- data/spec/support/test/google_unittest_import.pb.rb +39 -0
- data/spec/support/test/google_unittest_import.proto +64 -0
- data/spec/support/test/google_unittest_import_public.pb.rb +10 -0
- data/spec/support/test/google_unittest_import_public.proto +38 -0
- data/spec/support/test/multi_field_extensions.pb.rb +58 -0
- data/spec/support/test/multi_field_extensions.proto +33 -0
- data/spec/support/test/resource.pb.rb +119 -0
- data/spec/support/test/resource.proto +94 -0
- data/spec/support/test/resource_service.rb +23 -0
- data/spec/support/test_app_file.rb +2 -0
- metadata +502 -0
data/proto/rpc.proto
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
// Copyright (c) 2009 Shardul Deo
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
8
|
+
// furnished to do so, subject to the following conditions:
|
9
|
+
//
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
11
|
+
// all copies or substantial portions of the Software.
|
12
|
+
//
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
// THE SOFTWARE.
|
20
|
+
|
21
|
+
// Authors: Shardul Deo, BJ Neilsen
|
22
|
+
//
|
23
|
+
// Protobufs needed for socket rpcs.
|
24
|
+
|
25
|
+
package protobuf.socketrpc;
|
26
|
+
|
27
|
+
message Request
|
28
|
+
{
|
29
|
+
required string service_name = 1; // Fully- qualified Service class name
|
30
|
+
required string method_name = 2; // Service method to invoke
|
31
|
+
optional bytes request_proto = 3; // Serialized request bytes
|
32
|
+
optional string caller = 4; // Calling hostname or address
|
33
|
+
}
|
34
|
+
|
35
|
+
message Response
|
36
|
+
{
|
37
|
+
optional bytes response_proto = 1; // Serialized response
|
38
|
+
optional string error = 2; // Error message, if any
|
39
|
+
optional bool callback = 3 [default = false]; // Was callback invoked (not sure what this is for)
|
40
|
+
optional ErrorReason error_reason = 4; // Error Reason
|
41
|
+
}
|
42
|
+
|
43
|
+
// Possible error reasons
|
44
|
+
// The server-side errors are returned in the response from the server.
|
45
|
+
// The client-side errors are returned by the client-side code when it doesn't
|
46
|
+
// have a response from the server.
|
47
|
+
enum ErrorReason
|
48
|
+
{
|
49
|
+
// Server-side errors
|
50
|
+
BAD_REQUEST_DATA = 0; // Server received bad request data
|
51
|
+
BAD_REQUEST_PROTO = 1; // Server received bad request proto
|
52
|
+
SERVICE_NOT_FOUND = 2; // Service not found on server
|
53
|
+
METHOD_NOT_FOUND = 3; // Method not found on server
|
54
|
+
RPC_ERROR = 4; // Rpc threw exception on server
|
55
|
+
RPC_FAILED = 5; // Rpc failed on server
|
56
|
+
|
57
|
+
// Client-side errors (these are returned by the client-side code)
|
58
|
+
INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto
|
59
|
+
BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto
|
60
|
+
UNKNOWN_HOST = 8; // Could not find supplied host
|
61
|
+
IO_ERROR = 9; // I/O error while communicating with server
|
62
|
+
}
|
data/protobuf.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
$LOAD_PATH.push ::File.expand_path("../lib", __FILE__)
|
3
|
+
require "protobuf/version"
|
4
|
+
|
5
|
+
::Gem::Specification.new do |s|
|
6
|
+
s.name = 'prepor-protobuf'
|
7
|
+
s.version = ::Protobuf::VERSION
|
8
|
+
s.date = ::Time.now.strftime('%Y-%m-%d')
|
9
|
+
s.license = 'MIT'
|
10
|
+
|
11
|
+
s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen', 'Adam Hutchison']
|
12
|
+
s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com', 'liveh2o@gmail.com']
|
13
|
+
s.homepage = 'https://github.com/localshred/protobuf'
|
14
|
+
s.summary = "Google Protocol Buffers serialization and RPC implementation for Ruby."
|
15
|
+
s.description = s.summary
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'activesupport', '>= 3.2'
|
23
|
+
s.add_dependency 'middleware'
|
24
|
+
s.add_dependency 'thor'
|
25
|
+
s.add_dependency 'thread_safe'
|
26
|
+
|
27
|
+
s.add_development_dependency 'ffi-rzmq'
|
28
|
+
s.add_development_dependency 'rake'
|
29
|
+
s.add_development_dependency 'rspec', '>= 3.0'
|
30
|
+
s.add_development_dependency 'rubocop'
|
31
|
+
s.add_development_dependency 'simplecov'
|
32
|
+
s.add_development_dependency 'timecop'
|
33
|
+
s.add_development_dependency 'yard'
|
34
|
+
|
35
|
+
# debuggers only work in MRI
|
36
|
+
if RUBY_ENGINE.to_sym == :ruby
|
37
|
+
# we don't support MRI < 1.9.3
|
38
|
+
pry_debugger = if RUBY_VERSION < '2.0.0'
|
39
|
+
'pry-debugger'
|
40
|
+
else
|
41
|
+
'pry-byebug'
|
42
|
+
end
|
43
|
+
|
44
|
+
s.add_development_dependency pry_debugger
|
45
|
+
s.add_development_dependency 'pry-stack_explorer'
|
46
|
+
else
|
47
|
+
s.add_development_dependency 'pry'
|
48
|
+
end
|
49
|
+
|
50
|
+
s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby
|
51
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'protobuf/socket'
|
3
|
+
require 'support/all'
|
4
|
+
require 'support/test/resource_service'
|
5
|
+
|
6
|
+
case RUBY_ENGINE.to_sym
|
7
|
+
when :ruby
|
8
|
+
require 'ruby-prof'
|
9
|
+
when :rbx
|
10
|
+
require 'rubinius/profiler'
|
11
|
+
when :jruby
|
12
|
+
require 'jruby/profiler'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Including a way to turn on debug logger for spec runs
|
16
|
+
if ENV["DEBUG"]
|
17
|
+
puts 'debugging'
|
18
|
+
debug_log = File.expand_path('../../../debug_bench.log', __FILE__)
|
19
|
+
Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG)
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :benchmark do
|
23
|
+
|
24
|
+
def benchmark_wrapper(global_bench = nil)
|
25
|
+
if global_bench
|
26
|
+
yield global_bench
|
27
|
+
else
|
28
|
+
Benchmark.bm(10) do |bench|
|
29
|
+
yield bench
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def sock_client_sock_server(number_tests, test_length, global_bench = nil)
|
35
|
+
load "protobuf/socket.rb"
|
36
|
+
|
37
|
+
port = 1000 + Kernel.rand(2**16 - 1000)
|
38
|
+
|
39
|
+
StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do
|
40
|
+
client = ::Test::ResourceService.client(:port => port)
|
41
|
+
|
42
|
+
benchmark_wrapper(global_bench) do |bench|
|
43
|
+
bench.report("SS / SC") do
|
44
|
+
Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def zmq_client_zmq_server(number_tests, test_length, global_bench = nil)
|
51
|
+
load "protobuf/zmq.rb"
|
52
|
+
|
53
|
+
port = 1000 + Kernel.rand(2**16 - 1000)
|
54
|
+
|
55
|
+
StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do
|
56
|
+
client = ::Test::ResourceService.client(:port => port)
|
57
|
+
|
58
|
+
benchmark_wrapper(global_bench) do |bench|
|
59
|
+
bench.report("ZS / ZC") do
|
60
|
+
Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "benchmark ZMQ client with ZMQ server"
|
67
|
+
task :zmq_client_zmq_server, [:number, :length] do |_task, args|
|
68
|
+
args.with_defaults(:number => 1000, :length => 100)
|
69
|
+
zmq_client_zmq_server(args[:number], args[:length])
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "benchmark ZMQ client with ZMQ server and profile"
|
73
|
+
task :zmq_profile, [:number, :length, :profile_output] do |_task, args|
|
74
|
+
args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}")
|
75
|
+
|
76
|
+
profile_code(args[:profile_output]) do
|
77
|
+
zmq_client_zmq_server(args[:number], args[:length])
|
78
|
+
end
|
79
|
+
|
80
|
+
puts args[:profile_output]
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "benchmark Protobuf Message #new"
|
84
|
+
task :profile_protobuf_new, [:number, :profile_output] do |_task, args|
|
85
|
+
args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
|
86
|
+
create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
|
87
|
+
profile_code(args[:profile_output]) do
|
88
|
+
Integer(args[:number]).times { Test::Resource.new(create_params) }
|
89
|
+
end
|
90
|
+
|
91
|
+
puts args[:profile_output]
|
92
|
+
end
|
93
|
+
|
94
|
+
desc "benchmark Protobuf Message #serialize"
|
95
|
+
task :profile_protobuf_serialize, [:number, :profile_output] do |_task, args|
|
96
|
+
args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
|
97
|
+
create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
|
98
|
+
profile_code(args[:profile_output]) do
|
99
|
+
Integer(args[:number]).times { Test::Resource.new(create_params).serialize }
|
100
|
+
end
|
101
|
+
|
102
|
+
puts args[:profile_output]
|
103
|
+
end
|
104
|
+
|
105
|
+
def profile_code(output, &block)
|
106
|
+
case RUBY_ENGINE.to_sym
|
107
|
+
when :ruby
|
108
|
+
profile_data = RubyProf.profile(&block)
|
109
|
+
RubyProf::FlatPrinter.new(profile_data).print(:path => output)
|
110
|
+
when :rbx
|
111
|
+
profiler = Rubinius::Profiler::Instrumenter.new
|
112
|
+
profiler.profile(false, &block)
|
113
|
+
File.open(output, 'w') do |f|
|
114
|
+
profiler.show(f)
|
115
|
+
end
|
116
|
+
when :jruby
|
117
|
+
profile_data = JRuby::Profiler.profile(&block)
|
118
|
+
File.open(output, 'w') do |f|
|
119
|
+
JRuby::Profiler::FlatProfilePrinter.new(profile_data).printProfile(f)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
desc "benchmark Socket client with Socket server"
|
125
|
+
task :sock_client_sock_server, [:number, :length] do |_task, args|
|
126
|
+
args.with_defaults(:number => 1000, :length => 100)
|
127
|
+
sock_client_sock_server(args[:number], args[:length])
|
128
|
+
end
|
129
|
+
|
130
|
+
desc "benchmark server performance"
|
131
|
+
task :servers, [:number, :length] do |_task, args|
|
132
|
+
args.with_defaults(:number => 1000, :length => 100)
|
133
|
+
|
134
|
+
Benchmark.bm(10) do |bench|
|
135
|
+
zmq_client_zmq_server(args[:number], args[:length], bench)
|
136
|
+
sock_client_sock_server(args[:number], args[:length], bench)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'protobuf/code_generator'
|
4
|
+
|
5
|
+
RSpec.describe 'protoc-gen-ruby' do
|
6
|
+
let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) }
|
7
|
+
let(:package) { 'test' }
|
8
|
+
let(:request_bytes) do
|
9
|
+
::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(
|
10
|
+
:proto_file => [{ :package => package }],
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'reads the serialized request bytes and outputs serialized response bytes' do
|
15
|
+
::IO.popen(binpath, 'w+') do |pipe|
|
16
|
+
pipe.write(request_bytes)
|
17
|
+
pipe.close_write # needed so we can implicitly read until EOF
|
18
|
+
response_bytes = pipe.read
|
19
|
+
response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(response_bytes)
|
20
|
+
expect(response.file.first.content).to include("module #{package.titleize}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/data/data.bin
ADDED
data/spec/data/types.bin
ADDED
Binary file
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ::Protobuf do
|
4
|
+
it "correctly encodes all types" do
|
5
|
+
message = GoogleUnittest::TestAllTypes.new(
|
6
|
+
:optional_int32 => 101,
|
7
|
+
:optional_int64 => 102,
|
8
|
+
:optional_uint32 => 103,
|
9
|
+
:optional_uint64 => 104,
|
10
|
+
:optional_sint32 => 105,
|
11
|
+
:optional_sint64 => 106,
|
12
|
+
:optional_fixed32 => 107,
|
13
|
+
:optional_fixed64 => 108,
|
14
|
+
:optional_sfixed32 => 109,
|
15
|
+
:optional_sfixed64 => 110,
|
16
|
+
:optional_float => 111,
|
17
|
+
:optional_double => 112,
|
18
|
+
:optional_bool => true,
|
19
|
+
:optional_string => "115",
|
20
|
+
:optional_bytes => "116",
|
21
|
+
:optional_nested_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 118),
|
22
|
+
:optional_foreign_message => GoogleUnittest::ForeignMessage.new(:c => 119),
|
23
|
+
:optional_import_message => GoogleUnittestImport::ImportMessage.new(:d => 120),
|
24
|
+
:optional_nested_enum => GoogleUnittest::TestAllTypes::NestedEnum::BAZ,
|
25
|
+
:optional_foreign_enum => GoogleUnittest::ForeignEnum::FOREIGN_BAZ,
|
26
|
+
:optional_import_enum => GoogleUnittestImport::ImportEnum::IMPORT_BAZ,
|
27
|
+
:optional_string_piece => "124",
|
28
|
+
:optional_cord => "125",
|
29
|
+
:optional_public_import_message => GoogleUnittestImport::PublicImportMessage.new(:e => 126),
|
30
|
+
:optional_lazy_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 127),
|
31
|
+
:repeated_int32 => [201, 301],
|
32
|
+
:repeated_int64 => [202, 302],
|
33
|
+
:repeated_uint32 => [203, 303],
|
34
|
+
:repeated_uint64 => [204, 304],
|
35
|
+
:repeated_sint32 => [205, 305],
|
36
|
+
:repeated_sint64 => [206, 306],
|
37
|
+
:repeated_fixed32 => [207, 307],
|
38
|
+
:repeated_fixed64 => [208, 308],
|
39
|
+
:repeated_sfixed32 => [209, 309],
|
40
|
+
:repeated_sfixed64 => [210, 310],
|
41
|
+
:repeated_float => [211, 311],
|
42
|
+
:repeated_double => [212, 312],
|
43
|
+
:repeated_bool => [true, false],
|
44
|
+
:repeated_string => ["215", "315"],
|
45
|
+
:repeated_bytes => ["216", "316"],
|
46
|
+
:repeated_nested_message => [
|
47
|
+
::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 218),
|
48
|
+
::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 318),
|
49
|
+
],
|
50
|
+
:repeated_foreign_message => [
|
51
|
+
::GoogleUnittest::ForeignMessage.new(:c => 219),
|
52
|
+
::GoogleUnittest::ForeignMessage.new(:c => 319),
|
53
|
+
],
|
54
|
+
:repeated_import_message => [
|
55
|
+
::GoogleUnittestImport::ImportMessage.new(:d => 220),
|
56
|
+
::GoogleUnittestImport::ImportMessage.new(:d => 320),
|
57
|
+
],
|
58
|
+
:repeated_nested_enum => [
|
59
|
+
::GoogleUnittest::TestAllTypes::NestedEnum::BAR,
|
60
|
+
::GoogleUnittest::TestAllTypes::NestedEnum::BAZ,
|
61
|
+
],
|
62
|
+
:repeated_foreign_enum => [
|
63
|
+
::GoogleUnittest::ForeignEnum::FOREIGN_BAR,
|
64
|
+
::GoogleUnittest::ForeignEnum::FOREIGN_BAZ,
|
65
|
+
],
|
66
|
+
:repeated_import_enum => [
|
67
|
+
::GoogleUnittestImport::ImportEnum::IMPORT_BAR,
|
68
|
+
::GoogleUnittestImport::ImportEnum::IMPORT_BAZ,
|
69
|
+
],
|
70
|
+
:repeated_string_piece => ["224", "324"],
|
71
|
+
:repeated_cord => ["225", "325"],
|
72
|
+
:repeated_lazy_message => [
|
73
|
+
::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 227),
|
74
|
+
::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 327),
|
75
|
+
],
|
76
|
+
:default_int32 => 401,
|
77
|
+
:default_int64 => 402,
|
78
|
+
:default_uint32 => 403,
|
79
|
+
:default_uint64 => 404,
|
80
|
+
:default_sint32 => 405,
|
81
|
+
:default_sint64 => 406,
|
82
|
+
:default_fixed32 => 407,
|
83
|
+
:default_fixed64 => 408,
|
84
|
+
:default_sfixed32 => 409,
|
85
|
+
:default_sfixed64 => 410,
|
86
|
+
:default_float => 411,
|
87
|
+
:default_double => 412,
|
88
|
+
:default_bool => false,
|
89
|
+
:default_string => "415",
|
90
|
+
:default_bytes => "416",
|
91
|
+
:default_nested_enum => ::GoogleUnittest::TestAllTypes::NestedEnum::FOO,
|
92
|
+
:default_foreign_enum => ::GoogleUnittest::ForeignEnum::FOREIGN_FOO,
|
93
|
+
:default_import_enum => ::GoogleUnittestImport::ImportEnum::IMPORT_FOO,
|
94
|
+
:default_string_piece => "424",
|
95
|
+
:default_cord => "425",
|
96
|
+
)
|
97
|
+
|
98
|
+
data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__)
|
99
|
+
data = File.open(data_file_path, 'rb') do |file|
|
100
|
+
file.read
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(data).to eq(message.serialize_to_string)
|
104
|
+
end
|
105
|
+
end
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spec/support/test/resource_service'
|
3
|
+
|
4
|
+
RSpec.describe 'works through class inheritance' do
|
5
|
+
module Corp
|
6
|
+
module Protobuf
|
7
|
+
class Error < ::Protobuf::Message
|
8
|
+
required :string, :foo, 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
module Corp
|
13
|
+
class ErrorHandler < Corp::Protobuf::Error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:args) { { :foo => 'bar' } }
|
18
|
+
let(:parent_class) { Corp::Protobuf::Error }
|
19
|
+
let(:inherited_class) { Corp::ErrorHandler }
|
20
|
+
|
21
|
+
specify '#encode' do
|
22
|
+
expected_result = "\n\x03bar"
|
23
|
+
expected_result.force_encoding(Encoding::BINARY)
|
24
|
+
expect(parent_class.new(args).encode).to eq(expected_result)
|
25
|
+
expect(inherited_class.new(args).encode).to eq(expected_result)
|
26
|
+
end
|
27
|
+
|
28
|
+
specify '#to_hash' do
|
29
|
+
expect(parent_class.new(args).to_hash).to eq(args)
|
30
|
+
expect(inherited_class.new(args).to_hash).to eq(args)
|
31
|
+
end
|
32
|
+
|
33
|
+
specify '#to_json' do
|
34
|
+
expect(parent_class.new(args).to_json).to eq(args.to_json)
|
35
|
+
expect(inherited_class.new(args).to_json).to eq(args.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
specify '.encode' do
|
39
|
+
expected_result = "\n\x03bar"
|
40
|
+
expected_result.force_encoding(Encoding::BINARY)
|
41
|
+
expect(parent_class.encode(args)).to eq(expected_result)
|
42
|
+
expect(inherited_class.encode(args)).to eq(expected_result)
|
43
|
+
end
|
44
|
+
|
45
|
+
specify '.decode' do
|
46
|
+
raw_value = "\n\x03bar"
|
47
|
+
raw_value.force_encoding(Encoding::BINARY)
|
48
|
+
expect(parent_class.decode(raw_value).to_hash).to eq(args)
|
49
|
+
expect(inherited_class.decode(raw_value).to_hash).to eq(args)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spec/support/test/resource_service'
|
3
|
+
|
4
|
+
RSpec.describe 'Functional Socket Client' do
|
5
|
+
before(:all) do
|
6
|
+
load "protobuf/socket.rb"
|
7
|
+
@options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
|
8
|
+
@runner = ::Protobuf::Rpc::SocketRunner.new(@options)
|
9
|
+
@server_thread = Thread.new(@runner) { |runner| runner.run }
|
10
|
+
Thread.pass until @runner.running?
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
@runner.stop
|
15
|
+
@server_thread.join
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'runs fine when required fields are set' do
|
19
|
+
expect do
|
20
|
+
client = ::Test::ResourceService.client
|
21
|
+
|
22
|
+
client.find(:name => 'Test Name', :active => true) do |c|
|
23
|
+
c.on_success do |succ|
|
24
|
+
expect(succ.name).to eq("Test Name")
|
25
|
+
expect(succ.status).to eq(::Test::StatusType::ENABLED)
|
26
|
+
end
|
27
|
+
|
28
|
+
c.on_failure do |err|
|
29
|
+
fail err.inspect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end.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 { fail "shouldn't pass" }
|
42
|
+
c.on_failure { |e| error = e }
|
43
|
+
end
|
44
|
+
|
45
|
+
expect(error.message).to match(/Required field.*does not have a value/)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'calls the on_failure callback when the request type is wrong' do
|
49
|
+
error = nil
|
50
|
+
request = ::Test::Resource.new(:name => 'Test Name')
|
51
|
+
client = ::Test::ResourceService.client
|
52
|
+
|
53
|
+
client.find(request) do |c|
|
54
|
+
c.on_success { fail "shouldn't pass" }
|
55
|
+
c.on_failure { |e| error = e }
|
56
|
+
end
|
57
|
+
expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i)
|
58
|
+
end
|
59
|
+
end
|