protobuf-cucumber 3.10.4
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 +70 -0
- data/.rubocop_todo.yml +145 -0
- data/.travis.yml +40 -0
- data/.yardopts +5 -0
- data/CHANGES.md +344 -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 +22 -0
- data/bin/rpc_server +5 -0
- data/install-protobuf.sh +28 -0
- data/lib/protobuf.rb +129 -0
- data/lib/protobuf/cli.rb +257 -0
- data/lib/protobuf/code_generator.rb +120 -0
- data/lib/protobuf/decoder.rb +28 -0
- data/lib/protobuf/deprecation.rb +117 -0
- data/lib/protobuf/descriptors.rb +3 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +62 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +301 -0
- data/lib/protobuf/encoder.rb +11 -0
- data/lib/protobuf/enum.rb +365 -0
- data/lib/protobuf/exceptions.rb +9 -0
- data/lib/protobuf/field.rb +74 -0
- data/lib/protobuf/field/base_field.rb +380 -0
- data/lib/protobuf/field/base_field_object_definitions.rb +504 -0
- data/lib/protobuf/field/bool_field.rb +64 -0
- data/lib/protobuf/field/bytes_field.rb +78 -0
- data/lib/protobuf/field/double_field.rb +25 -0
- data/lib/protobuf/field/enum_field.rb +61 -0
- data/lib/protobuf/field/field_array.rb +104 -0
- data/lib/protobuf/field/field_hash.rb +122 -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 +43 -0
- data/lib/protobuf/field/int32_field.rb +21 -0
- data/lib/protobuf/field/int64_field.rb +34 -0
- data/lib/protobuf/field/integer_field.rb +23 -0
- data/lib/protobuf/field/message_field.rb +51 -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 +51 -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 +77 -0
- data/lib/protobuf/generators/base.rb +85 -0
- data/lib/protobuf/generators/enum_generator.rb +39 -0
- data/lib/protobuf/generators/extension_generator.rb +27 -0
- data/lib/protobuf/generators/field_generator.rb +193 -0
- data/lib/protobuf/generators/file_generator.rb +262 -0
- data/lib/protobuf/generators/group_generator.rb +122 -0
- data/lib/protobuf/generators/message_generator.rb +104 -0
- data/lib/protobuf/generators/option_generator.rb +17 -0
- data/lib/protobuf/generators/printable.rb +160 -0
- data/lib/protobuf/generators/service_generator.rb +50 -0
- data/lib/protobuf/lifecycle.rb +33 -0
- data/lib/protobuf/logging.rb +39 -0
- data/lib/protobuf/message.rb +260 -0
- data/lib/protobuf/message/fields.rb +233 -0
- data/lib/protobuf/message/serialization.rb +85 -0
- data/lib/protobuf/optionable.rb +70 -0
- data/lib/protobuf/rpc/buffer.rb +78 -0
- data/lib/protobuf/rpc/client.rb +140 -0
- data/lib/protobuf/rpc/connectors/base.rb +221 -0
- data/lib/protobuf/rpc/connectors/ping.rb +89 -0
- data/lib/protobuf/rpc/connectors/socket.rb +78 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +319 -0
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +50 -0
- data/lib/protobuf/rpc/env.rb +60 -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 +40 -0
- data/lib/protobuf/rpc/middleware/logger.rb +95 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +79 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/rpc.pb.rb +64 -0
- data/lib/protobuf/rpc/rpc_method.rb +16 -0
- data/lib/protobuf/rpc/server.rb +39 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +121 -0
- data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
- data/lib/protobuf/rpc/servers/socket_runner.rb +46 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +194 -0
- data/lib/protobuf/rpc/servers/zmq/server.rb +321 -0
- data/lib/protobuf/rpc/servers/zmq/util.rb +48 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
- data/lib/protobuf/rpc/servers/zmq_runner.rb +70 -0
- data/lib/protobuf/rpc/service.rb +172 -0
- data/lib/protobuf/rpc/service_directory.rb +261 -0
- data/lib/protobuf/rpc/service_dispatcher.rb +45 -0
- data/lib/protobuf/rpc/service_filters.rb +250 -0
- data/lib/protobuf/rpc/stat.rb +119 -0
- data/lib/protobuf/socket.rb +21 -0
- data/lib/protobuf/tasks.rb +1 -0
- data/lib/protobuf/tasks/compile.rake +80 -0
- data/lib/protobuf/varint.rb +20 -0
- data/lib/protobuf/varint_pure.rb +31 -0
- data/lib/protobuf/version.rb +3 -0
- data/lib/protobuf/wire_type.rb +10 -0
- data/lib/protobuf/zmq.rb +21 -0
- data/profile.html +5103 -0
- data/proto/dynamic_discovery.proto +44 -0
- data/proto/google/protobuf/compiler/plugin.proto +147 -0
- data/proto/google/protobuf/descriptor.proto +779 -0
- data/proto/rpc.proto +69 -0
- data/protobuf-cucumber.gemspec +57 -0
- data/spec/benchmark/tasks.rb +143 -0
- data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
- data/spec/encoding/all_types_spec.rb +103 -0
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/class_inheritance_spec.rb +52 -0
- data/spec/functional/code_generator_spec.rb +58 -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 +317 -0
- data/spec/lib/protobuf/code_generator_spec.rb +87 -0
- data/spec/lib/protobuf/enum_spec.rb +307 -0
- data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
- data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/enum_field_spec.rb +44 -0
- data/spec/lib/protobuf/field/field_array_spec.rb +105 -0
- data/spec/lib/protobuf/field/field_hash_spec.rb +168 -0
- data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
- data/spec/lib/protobuf/field/int32_field_spec.rb +120 -0
- data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
- data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +79 -0
- data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field_spec.rb +192 -0
- data/spec/lib/protobuf/generators/base_spec.rb +154 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +82 -0
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +42 -0
- data/spec/lib/protobuf/generators/field_generator_spec.rb +197 -0
- data/spec/lib/protobuf/generators/file_generator_spec.rb +119 -0
- data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
- data/spec/lib/protobuf/generators/service_generator_spec.rb +99 -0
- data/spec/lib/protobuf/lifecycle_spec.rb +94 -0
- data/spec/lib/protobuf/message_spec.rb +944 -0
- data/spec/lib/protobuf/optionable_spec.rb +265 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +226 -0
- data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +34 -0
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +110 -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 +91 -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 +35 -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 +101 -0
- data/spec/lib/protobuf/varint_spec.rb +29 -0
- data/spec/lib/protobuf_spec.rb +105 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/all.rb +6 -0
- data/spec/support/packed_field.rb +23 -0
- data/spec/support/protos/all_types.data.bin +0 -0
- data/spec/support/protos/all_types.data.txt +119 -0
- data/spec/support/protos/enum.pb.rb +63 -0
- data/spec/support/protos/enum.proto +37 -0
- data/spec/support/protos/extreme_values.data.bin +0 -0
- data/spec/support/protos/google_unittest.bin +0 -0
- data/spec/support/protos/google_unittest.pb.rb +798 -0
- data/spec/support/protos/google_unittest.proto +884 -0
- data/spec/support/protos/google_unittest_custom_options.bin +0 -0
- data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
- data/spec/support/protos/google_unittest_custom_options.proto +424 -0
- data/spec/support/protos/google_unittest_import.pb.rb +55 -0
- data/spec/support/protos/google_unittest_import.proto +73 -0
- data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
- data/spec/support/protos/google_unittest_import_public.proto +41 -0
- data/spec/support/protos/map-test.bin +157 -0
- data/spec/support/protos/map-test.pb.rb +85 -0
- data/spec/support/protos/map-test.proto +68 -0
- data/spec/support/protos/multi_field_extensions.pb.rb +59 -0
- data/spec/support/protos/multi_field_extensions.proto +35 -0
- data/spec/support/protos/resource.pb.rb +172 -0
- data/spec/support/protos/resource.proto +137 -0
- data/spec/support/resource_service.rb +23 -0
- data/spec/support/server.rb +65 -0
- data/spec/support/test_app_file.rb +2 -0
- data/varint_prof.rb +82 -0
- metadata +579 -0
data/proto/rpc.proto
ADDED
@@ -0,0 +1,69 @@
|
|
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
|
+
repeated Header headers = 5; // General purpose request headers
|
34
|
+
}
|
35
|
+
|
36
|
+
message Response
|
37
|
+
{
|
38
|
+
optional bytes response_proto = 1; // Serialized response
|
39
|
+
optional string error = 2; // Error message, if any
|
40
|
+
optional bool callback = 3 [default = false]; // Was callback invoked (not sure what this is for)
|
41
|
+
optional ErrorReason error_reason = 4; // Error Reason
|
42
|
+
optional string server = 5; // Server hostname or address
|
43
|
+
}
|
44
|
+
|
45
|
+
message Header {
|
46
|
+
required string key = 1;
|
47
|
+
optional string value = 2;
|
48
|
+
}
|
49
|
+
|
50
|
+
// Possible error reasons
|
51
|
+
// The server-side errors are returned in the response from the server.
|
52
|
+
// The client-side errors are returned by the client-side code when it doesn't
|
53
|
+
// have a response from the server.
|
54
|
+
enum ErrorReason
|
55
|
+
{
|
56
|
+
// Server-side errors
|
57
|
+
BAD_REQUEST_DATA = 0; // Server received bad request data
|
58
|
+
BAD_REQUEST_PROTO = 1; // Server received bad request proto
|
59
|
+
SERVICE_NOT_FOUND = 2; // Service not found on server
|
60
|
+
METHOD_NOT_FOUND = 3; // Method not found on server
|
61
|
+
RPC_ERROR = 4; // Rpc threw exception on server
|
62
|
+
RPC_FAILED = 5; // Rpc failed on server
|
63
|
+
|
64
|
+
// Client-side errors (these are returned by the client-side code)
|
65
|
+
INVALID_REQUEST_PROTO = 6; // Rpc was called with invalid request proto
|
66
|
+
BAD_RESPONSE_PROTO = 7; // Server returned a bad response proto
|
67
|
+
UNKNOWN_HOST = 8; // Could not find supplied host
|
68
|
+
IO_ERROR = 9; // I/O error while communicating with server
|
69
|
+
}
|
@@ -0,0 +1,57 @@
|
|
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 = 'protobuf-cucumber'
|
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
|
+
# Hack, as Rails 5 requires Ruby version >= 2.2.2.
|
23
|
+
active_support_max_version = "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
|
24
|
+
s.add_dependency "activesupport", '>= 3.2', active_support_max_version
|
25
|
+
s.add_dependency 'middleware'
|
26
|
+
s.add_dependency 'thor'
|
27
|
+
s.add_dependency 'thread_safe'
|
28
|
+
|
29
|
+
s.add_development_dependency 'benchmark-ips'
|
30
|
+
s.add_development_dependency 'ffi-rzmq'
|
31
|
+
s.add_development_dependency 'rake', '< 11.0' # Rake 11.0.1 removes the last_comment method which rspec-core (< 3.4.4) uses
|
32
|
+
s.add_development_dependency 'rspec', '>= 3.0'
|
33
|
+
s.add_development_dependency "rubocop", "~> 0.38.0"
|
34
|
+
s.add_development_dependency "parser", "2.3.0.6" # Locked this down since 2.3.0.7 causes issues. https://github.com/bbatsov/rubocop/pull/2984
|
35
|
+
s.add_development_dependency 'simplecov'
|
36
|
+
s.add_development_dependency 'timecop'
|
37
|
+
s.add_development_dependency 'yard'
|
38
|
+
|
39
|
+
# debuggers only work in MRI
|
40
|
+
if RUBY_ENGINE.to_sym == :ruby
|
41
|
+
# we don't support MRI < 1.9.3
|
42
|
+
pry_debugger = if RUBY_VERSION < '2.0.0'
|
43
|
+
'pry-debugger'
|
44
|
+
else
|
45
|
+
'pry-byebug'
|
46
|
+
end
|
47
|
+
|
48
|
+
s.add_development_dependency pry_debugger
|
49
|
+
s.add_development_dependency 'pry-stack_explorer'
|
50
|
+
|
51
|
+
s.add_development_dependency 'varint'
|
52
|
+
s.add_development_dependency 'ruby-prof'
|
53
|
+
elsif RUBY_PLATFORM =~ /java/i
|
54
|
+
s.add_development_dependency 'fast_blank_java'
|
55
|
+
s.add_development_dependency 'pry'
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'protobuf'
|
3
|
+
require 'protobuf/socket'
|
4
|
+
require 'support/all'
|
5
|
+
require 'spec_helper'
|
6
|
+
require SUPPORT_PATH.join('resource_service')
|
7
|
+
|
8
|
+
case RUBY_ENGINE.to_sym
|
9
|
+
when :ruby
|
10
|
+
require 'ruby-prof'
|
11
|
+
when :rbx
|
12
|
+
require 'rubinius/profiler'
|
13
|
+
when :jruby
|
14
|
+
require 'jruby/profiler'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Including a way to turn on debug logger for spec runs
|
18
|
+
if ENV["DEBUG"]
|
19
|
+
puts 'debugging'
|
20
|
+
debug_log = File.expand_path('../../../debug_bench.log', __FILE__)
|
21
|
+
Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG)
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :benchmark do
|
25
|
+
|
26
|
+
def benchmark_wrapper(global_bench = nil)
|
27
|
+
if global_bench
|
28
|
+
yield global_bench
|
29
|
+
else
|
30
|
+
Benchmark.bm(10) do |bench|
|
31
|
+
yield bench
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def sock_client_sock_server(number_tests, test_length, global_bench = nil)
|
37
|
+
load "protobuf/socket.rb"
|
38
|
+
|
39
|
+
port = 1000 + Kernel.rand(2**16 - 1000)
|
40
|
+
|
41
|
+
StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do
|
42
|
+
client = ::Test::ResourceService.client(:port => port)
|
43
|
+
|
44
|
+
benchmark_wrapper(global_bench) do |bench|
|
45
|
+
bench.report("SS / SC") do
|
46
|
+
Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def zmq_client_zmq_server(number_tests, test_length, global_bench = nil)
|
53
|
+
load "protobuf/zmq.rb"
|
54
|
+
|
55
|
+
port = 1000 + Kernel.rand(2**16 - 1000)
|
56
|
+
|
57
|
+
StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do
|
58
|
+
client = ::Test::ResourceService.client(:port => port)
|
59
|
+
|
60
|
+
benchmark_wrapper(global_bench) do |bench|
|
61
|
+
bench.report("ZS / ZC") do
|
62
|
+
Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "benchmark ZMQ client with ZMQ server"
|
69
|
+
task :zmq_client_zmq_server, [:number, :length] do |_task, args|
|
70
|
+
args.with_defaults(:number => 1000, :length => 100)
|
71
|
+
zmq_client_zmq_server(args[:number], args[:length])
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "benchmark ZMQ client with ZMQ server and profile"
|
75
|
+
task :zmq_profile, [:number, :length, :profile_output] do |_task, args|
|
76
|
+
args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}")
|
77
|
+
|
78
|
+
profile_code(args[:profile_output]) do
|
79
|
+
zmq_client_zmq_server(args[:number], args[:length])
|
80
|
+
end
|
81
|
+
|
82
|
+
puts args[:profile_output]
|
83
|
+
end
|
84
|
+
|
85
|
+
desc "benchmark Protobuf Message #new"
|
86
|
+
task :profile_protobuf_new, [:number, :profile_output] do |_task, args|
|
87
|
+
args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
|
88
|
+
create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
|
89
|
+
profile_code(args[:profile_output]) do
|
90
|
+
Integer(args[:number]).times { Test::Resource.new(create_params) }
|
91
|
+
end
|
92
|
+
|
93
|
+
puts args[:profile_output]
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "benchmark Protobuf Message #serialize"
|
97
|
+
task :profile_protobuf_serialize, [:number, :profile_output] do |_task, args|
|
98
|
+
args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}")
|
99
|
+
create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 }
|
100
|
+
profile_code(args[:profile_output]) do
|
101
|
+
Integer(args[:number]).times { Test::Resource.decode(Test::Resource.new(create_params).serialize) }
|
102
|
+
end
|
103
|
+
|
104
|
+
puts args[:profile_output]
|
105
|
+
end
|
106
|
+
|
107
|
+
def profile_code(output, &block)
|
108
|
+
case RUBY_ENGINE.to_sym
|
109
|
+
when :ruby
|
110
|
+
profile_data = RubyProf.profile(&block)
|
111
|
+
::File.open(output, "w") do |output_file|
|
112
|
+
RubyProf::FlatPrinter.new(profile_data).print(output_file)
|
113
|
+
end
|
114
|
+
when :rbx
|
115
|
+
profiler = Rubinius::Profiler::Instrumenter.new
|
116
|
+
profiler.profile(false, &block)
|
117
|
+
File.open(output, 'w') do |f|
|
118
|
+
profiler.show(f)
|
119
|
+
end
|
120
|
+
when :jruby
|
121
|
+
profile_data = JRuby::Profiler.profile(&block)
|
122
|
+
File.open(output, 'w') do |f|
|
123
|
+
JRuby::Profiler::FlatProfilePrinter.new(profile_data).printProfile(f)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
desc "benchmark Socket client with Socket server"
|
129
|
+
task :sock_client_sock_server, [:number, :length] do |_task, args|
|
130
|
+
args.with_defaults(:number => 1000, :length => 100)
|
131
|
+
sock_client_sock_server(args[:number], args[:length])
|
132
|
+
end
|
133
|
+
|
134
|
+
desc "benchmark server performance"
|
135
|
+
task :servers, [:number, :length] do |_task, args|
|
136
|
+
args.with_defaults(:number => 1000, :length => 100)
|
137
|
+
|
138
|
+
Benchmark.bm(10) do |bench|
|
139
|
+
zmq_client_zmq_server(args[:number], args[:length], bench)
|
140
|
+
sock_client_sock_server(args[:number], args[:length], bench)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
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
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require PROTOS_PATH.join('google_unittest.pb')
|
3
|
+
|
4
|
+
RSpec.describe ::Protobuf do
|
5
|
+
it "correctly encodes all types" do
|
6
|
+
message = Protobuf_unittest::TestAllTypes.new(
|
7
|
+
:optional_int32 => 101,
|
8
|
+
:optional_int64 => 102,
|
9
|
+
:optional_uint32 => 103,
|
10
|
+
:optional_uint64 => 104,
|
11
|
+
:optional_sint32 => 105,
|
12
|
+
:optional_sint64 => 106,
|
13
|
+
:optional_fixed32 => 107,
|
14
|
+
:optional_fixed64 => 108,
|
15
|
+
:optional_sfixed32 => 109,
|
16
|
+
:optional_sfixed64 => 110,
|
17
|
+
:optional_float => 111,
|
18
|
+
:optional_double => 112,
|
19
|
+
:optional_bool => true,
|
20
|
+
:optional_string => "115",
|
21
|
+
:optional_bytes => "116".force_encoding(Encoding::ASCII_8BIT),
|
22
|
+
:optional_nested_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 118),
|
23
|
+
:optional_foreign_message => Protobuf_unittest::ForeignMessage.new(:c => 119),
|
24
|
+
:optional_import_message => Protobuf_unittest_import::ImportMessage.new(:d => 120),
|
25
|
+
:optional_nested_enum => Protobuf_unittest::TestAllTypes::NestedEnum::BAZ,
|
26
|
+
:optional_foreign_enum => Protobuf_unittest::ForeignEnum::FOREIGN_BAZ,
|
27
|
+
:optional_import_enum => Protobuf_unittest_import::ImportEnum::IMPORT_BAZ,
|
28
|
+
:optional_string_piece => "124",
|
29
|
+
:optional_cord => "125",
|
30
|
+
:optional_public_import_message => Protobuf_unittest_import::PublicImportMessage.new(:e => 126),
|
31
|
+
:optional_lazy_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 127),
|
32
|
+
:repeated_int32 => [201, 301],
|
33
|
+
:repeated_int64 => [202, 302],
|
34
|
+
:repeated_uint32 => [203, 303],
|
35
|
+
:repeated_uint64 => [204, 304],
|
36
|
+
:repeated_sint32 => [205, 305],
|
37
|
+
:repeated_sint64 => [206, 306],
|
38
|
+
:repeated_fixed32 => [207, 307],
|
39
|
+
:repeated_fixed64 => [208, 308],
|
40
|
+
:repeated_sfixed32 => [209, 309],
|
41
|
+
:repeated_sfixed64 => [210, 310],
|
42
|
+
:repeated_float => [211, 311],
|
43
|
+
:repeated_double => [212, 312],
|
44
|
+
:repeated_bool => [true, false],
|
45
|
+
:repeated_string => ["215", "315"],
|
46
|
+
:repeated_bytes => ["216".force_encoding(Encoding::ASCII_8BIT), "316".force_encoding(Encoding::ASCII_8BIT)],
|
47
|
+
:repeated_nested_message => [
|
48
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 218),
|
49
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 318),
|
50
|
+
],
|
51
|
+
:repeated_foreign_message => [
|
52
|
+
::Protobuf_unittest::ForeignMessage.new(:c => 219),
|
53
|
+
::Protobuf_unittest::ForeignMessage.new(:c => 319),
|
54
|
+
],
|
55
|
+
:repeated_import_message => [
|
56
|
+
::Protobuf_unittest_import::ImportMessage.new(:d => 220),
|
57
|
+
::Protobuf_unittest_import::ImportMessage.new(:d => 320),
|
58
|
+
],
|
59
|
+
:repeated_nested_enum => [
|
60
|
+
::Protobuf_unittest::TestAllTypes::NestedEnum::BAR,
|
61
|
+
::Protobuf_unittest::TestAllTypes::NestedEnum::BAZ,
|
62
|
+
],
|
63
|
+
:repeated_foreign_enum => [
|
64
|
+
::Protobuf_unittest::ForeignEnum::FOREIGN_BAR,
|
65
|
+
::Protobuf_unittest::ForeignEnum::FOREIGN_BAZ,
|
66
|
+
],
|
67
|
+
:repeated_import_enum => [
|
68
|
+
::Protobuf_unittest_import::ImportEnum::IMPORT_BAR,
|
69
|
+
::Protobuf_unittest_import::ImportEnum::IMPORT_BAZ,
|
70
|
+
],
|
71
|
+
:repeated_string_piece => ["224", "324"],
|
72
|
+
:repeated_cord => ["225", "325"],
|
73
|
+
:repeated_lazy_message => [
|
74
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 227),
|
75
|
+
::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 327),
|
76
|
+
],
|
77
|
+
:default_int32 => 401,
|
78
|
+
:default_int64 => 402,
|
79
|
+
:default_uint32 => 403,
|
80
|
+
:default_uint64 => 404,
|
81
|
+
:default_sint32 => 405,
|
82
|
+
:default_sint64 => 406,
|
83
|
+
:default_fixed32 => 407,
|
84
|
+
:default_fixed64 => 408,
|
85
|
+
:default_sfixed32 => 409,
|
86
|
+
:default_sfixed64 => 410,
|
87
|
+
:default_float => 411,
|
88
|
+
:default_double => 412,
|
89
|
+
:default_bool => false,
|
90
|
+
:default_string => "415",
|
91
|
+
:default_bytes => "416".force_encoding(Encoding::ASCII_8BIT),
|
92
|
+
:default_nested_enum => ::Protobuf_unittest::TestAllTypes::NestedEnum::FOO,
|
93
|
+
:default_foreign_enum => ::Protobuf_unittest::ForeignEnum::FOREIGN_FOO,
|
94
|
+
:default_import_enum => ::Protobuf_unittest_import::ImportEnum::IMPORT_FOO,
|
95
|
+
:default_string_piece => "424",
|
96
|
+
:default_cord => "425",
|
97
|
+
)
|
98
|
+
|
99
|
+
data_file_path = PROTOS_PATH.join('all_types.data.bin')
|
100
|
+
data = File.open(data_file_path, 'rb', &:read)
|
101
|
+
expect(data).to eq(message.serialize_to_string)
|
102
|
+
end
|
103
|
+
end
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require SUPPORT_PATH.join('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
|