protobuf 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/protobuf.rb +19 -6
- data/lib/protobuf/cli.rb +10 -14
- data/lib/protobuf/field.rb +1 -1
- data/lib/protobuf/message.rb +4 -4
- data/lib/protobuf/rpc/client.rb +4 -4
- data/lib/protobuf/rpc/connector.rb +8 -12
- data/lib/protobuf/rpc/connectors/em_client.rb +2 -2
- data/lib/protobuf/rpc/servers/evented_runner.rb +2 -2
- data/lib/protobuf/rpc/servers/socket/server.rb +11 -10
- data/lib/protobuf/rpc/servers/zmq/broker.rb +17 -15
- data/lib/protobuf/rpc/servers/zmq/server.rb +4 -4
- data/lib/protobuf/rpc/servers/zmq/worker.rb +4 -6
- data/lib/protobuf/version.rb +1 -1
- data/spec/benchmark/tasks.rb +0 -3
- data/spec/functional/evented_server_spec.rb +0 -1
- data/spec/functional/socket_server_spec.rb +1 -2
- data/spec/functional/zmq_server_spec.rb +1 -2
- data/spec/lib/protobuf/rpc/client_spec.rb +0 -1
- data/spec/lib/protobuf/rpc/connector_spec.rb +9 -18
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +3 -5
- data/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +6 -3
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +0 -1
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +1 -2
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +4 -1
- data/spec/support/server.rb +2 -2
- metadata +32 -32
data/lib/protobuf.rb
CHANGED
@@ -7,10 +7,10 @@ require 'active_support/all'
|
|
7
7
|
module Protobuf
|
8
8
|
|
9
9
|
# See Protobuf#connector_type documentation.
|
10
|
-
|
10
|
+
CONNECTORS = [ :socket, :zmq, :evented ].freeze
|
11
11
|
|
12
12
|
# Default is Socket as it has no external dependencies.
|
13
|
-
|
13
|
+
DEFAULT_CONNECTOR = :socket
|
14
14
|
|
15
15
|
module_function
|
16
16
|
|
@@ -21,15 +21,14 @@ module Protobuf
|
|
21
21
|
# Symbol value which denotes the type of connector to use
|
22
22
|
# during client requests to an RPC server.
|
23
23
|
def self.connector_type
|
24
|
-
@_connector_type ||=
|
24
|
+
@_connector_type ||= DEFAULT_CONNECTOR
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.connector_type=(type)
|
28
|
-
raise ArgumentError, 'Invalid connector type given' unless
|
28
|
+
raise ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type)
|
29
29
|
@_connector_type = type
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
32
|
# GC Pause during server requests
|
34
33
|
#
|
35
34
|
# Default: false
|
@@ -70,4 +69,18 @@ end
|
|
70
69
|
|
71
70
|
require 'protobuf/rpc/client'
|
72
71
|
require 'protobuf/rpc/service'
|
73
|
-
|
72
|
+
|
73
|
+
env_connector_type = ENV.fetch('PB_CLIENT_TYPE') {
|
74
|
+
::Protobuf::DEFAULT_CONNECTOR
|
75
|
+
}.to_s.downcase.strip.to_sym
|
76
|
+
|
77
|
+
if ::Protobuf::CONNECTORS.include?(env_connector_type)
|
78
|
+
require "protobuf/#{env_connector_type}"
|
79
|
+
else
|
80
|
+
$stderr.puts <<-WARN
|
81
|
+
[WARNING] Require attempted on an invalid connector type '#{env_connector_type}'.
|
82
|
+
Falling back to default '#{::Protobuf::DEFAULT_CONNECTOR}' connector.
|
83
|
+
WARN
|
84
|
+
|
85
|
+
require "protobuf/#{::Protobuf::DEFAULT_CONNECTOR}"
|
86
|
+
end
|
data/lib/protobuf/cli.rb
CHANGED
@@ -16,7 +16,7 @@ module Protobuf
|
|
16
16
|
desc 'start APP_FILE', 'Run the RPC server in the given mode, preloading the given APP_FILE. This is the default task.'
|
17
17
|
|
18
18
|
option :host, :type => :string, :default => '127.0.0.1', :aliases => %w(-o), :desc => 'Host to bind.'
|
19
|
-
option :port, :type => :numeric, :default =>
|
19
|
+
option :port, :type => :numeric, :default => 9399, :aliases => %w(-p), :desc => 'Master Port to bind.'
|
20
20
|
|
21
21
|
option :backlog, :type => :numeric, :default => 100, :aliases => %w(-b), :desc => 'Backlog for listening socket when using Socket Server.'
|
22
22
|
option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.'
|
@@ -107,19 +107,15 @@ module Protobuf
|
|
107
107
|
# TODO add signal handling for hot-reloading the application.
|
108
108
|
def configure_traps
|
109
109
|
debug_say 'Configuring traps'
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
debug_say 'Registering QUIT', :blue
|
120
|
-
trap(:QUIT, &trap_block)
|
121
|
-
debug_say 'Registering TERM', :blue
|
122
|
-
trap(:TERM, &trap_block)
|
110
|
+
[:INT, :QUIT, :TERM].each do |signal|
|
111
|
+
debug_say "Registering signal trap for #{signal}", :blue
|
112
|
+
trap(signal) do
|
113
|
+
::Protobuf::Logger.info { 'RPC Server shutting down...' }
|
114
|
+
@start_aborted = true
|
115
|
+
@runner.stop
|
116
|
+
::Protobuf::Logger.info { 'Shutdown complete' }
|
117
|
+
end
|
118
|
+
end
|
123
119
|
end
|
124
120
|
|
125
121
|
# Say something if we're in debug mode.
|
data/lib/protobuf/field.rb
CHANGED
@@ -41,7 +41,7 @@ module Protobuf
|
|
41
41
|
::Protobuf::Field::BoolField
|
42
42
|
].freeze
|
43
43
|
|
44
|
-
def self.build(message_class, rule, type, name, tag, options={})
|
44
|
+
def self.build(message_class, rule, type, name, tag, options = {})
|
45
45
|
field_class = type_message_or_enum(type)
|
46
46
|
field_class.new(message_class, rule, type, name, tag, options)
|
47
47
|
end
|
data/lib/protobuf/message.rb
CHANGED
@@ -29,17 +29,17 @@ module Protobuf
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Define a required field. Don't use this method directly.
|
32
|
-
def self.required(type, name, tag, options={})
|
32
|
+
def self.required(type, name, tag, options = {})
|
33
33
|
define_field(:required, type, name, tag, options)
|
34
34
|
end
|
35
35
|
|
36
36
|
# Define a optional field. Don't use this method directly.
|
37
|
-
def self.optional(type, name, tag, options={})
|
37
|
+
def self.optional(type, name, tag, options = {})
|
38
38
|
define_field(:optional, type, name, tag, options)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Define a repeated field. Don't use this method directly.
|
42
|
-
def self.repeated(type, name, tag, options={})
|
42
|
+
def self.repeated(type, name, tag, options = {})
|
43
43
|
define_field(:repeated, type, name, tag, options)
|
44
44
|
end
|
45
45
|
|
@@ -111,7 +111,7 @@ module Protobuf
|
|
111
111
|
##
|
112
112
|
# Constructor
|
113
113
|
#
|
114
|
-
def initialize(values={})
|
114
|
+
def initialize(values = {})
|
115
115
|
values = values.to_hash
|
116
116
|
@values = {}
|
117
117
|
|
data/lib/protobuf/rpc/client.rb
CHANGED
@@ -26,10 +26,10 @@ module Protobuf
|
|
26
26
|
# :request => request
|
27
27
|
# })
|
28
28
|
#
|
29
|
-
def initialize(
|
30
|
-
raise "Invalid client configuration. Service must be defined." if
|
31
|
-
@connector = Connector.connector_for_client.new(
|
32
|
-
log_debug { sign_message("Initialized with options: #{
|
29
|
+
def initialize(options = {})
|
30
|
+
raise "Invalid client configuration. Service must be defined." if options[:service].nil?
|
31
|
+
@connector = Connector.connector_for_client.new(options)
|
32
|
+
log_debug { sign_message("Initialized with options: #{options.inspect}") }
|
33
33
|
end
|
34
34
|
|
35
35
|
def log_signature
|
@@ -3,19 +3,15 @@ module Protobuf
|
|
3
3
|
class Connector
|
4
4
|
|
5
5
|
# Returns a connector class for the pre-defined connector_type.
|
6
|
-
def self.connector_for_client
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
::Protobuf::Rpc::Connectors::Socket
|
15
|
-
end
|
6
|
+
def self.connector_for_client
|
7
|
+
case ::Protobuf.connector_type
|
8
|
+
when :evented then
|
9
|
+
::Protobuf::Rpc::Connectors::EventMachine
|
10
|
+
when :zmq then
|
11
|
+
::Protobuf::Rpc::Connectors::Zmq
|
12
|
+
else
|
13
|
+
::Protobuf::Rpc::Connectors::Socket
|
16
14
|
end
|
17
|
-
|
18
|
-
return @_connector
|
19
15
|
end
|
20
16
|
|
21
17
|
end
|
@@ -13,7 +13,7 @@ module Protobuf
|
|
13
13
|
##
|
14
14
|
# Constructor
|
15
15
|
#
|
16
|
-
def initialize(options={}, &failure_cb)
|
16
|
+
def initialize(options = {}, &failure_cb)
|
17
17
|
@failure_cb = failure_cb
|
18
18
|
@options = DEFAULT_OPTIONS.merge(options)
|
19
19
|
@response_buffer = ::Protobuf::Rpc::Buffer.new(:read)
|
@@ -27,7 +27,7 @@ module Protobuf
|
|
27
27
|
##
|
28
28
|
# Class Methods
|
29
29
|
#
|
30
|
-
def self.connect(options={})
|
30
|
+
def self.connect(options = {})
|
31
31
|
options = DEFAULT_OPTIONS.merge(options)
|
32
32
|
log_debug { sign_message("Connecting to server: #{options.inspect}") }
|
33
33
|
EM.connect(options[:host], options[:port], self, options)
|
@@ -6,10 +6,10 @@ module Protobuf
|
|
6
6
|
::EventMachine.stop_event_loop if ::EventMachine.reactor_running?
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.run(
|
9
|
+
def self.run(options)
|
10
10
|
# Startup and run the rpc server
|
11
11
|
::EventMachine.schedule do
|
12
|
-
::EventMachine.start_server(
|
12
|
+
::EventMachine.start_server(options[:host], options[:port], ::Protobuf::Rpc::Evented::Server)
|
13
13
|
end
|
14
14
|
|
15
15
|
# Join or start the reactor
|
@@ -9,9 +9,11 @@ module Protobuf
|
|
9
9
|
include ::Protobuf::Rpc::Server
|
10
10
|
include ::Protobuf::Logger::LogMethods
|
11
11
|
|
12
|
+
AUTO_COLLECT_TIMEOUT = 20 # seconds
|
13
|
+
|
12
14
|
def self.cleanup?
|
13
15
|
# every 10 connections run a cleanup routine after closing the response
|
14
|
-
@threads.size > (@
|
16
|
+
@threads.size > (@threshold - 1) && (@threads.size % @threshold) == 0
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.cleanup_threads
|
@@ -42,18 +44,17 @@ module Protobuf
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
def self.run(
|
47
|
+
def self.run(options = {})
|
46
48
|
log_debug { sign_message("Run") }
|
47
|
-
host =
|
48
|
-
port =
|
49
|
-
backlog =
|
50
|
-
|
51
|
-
auto_collect_timeout = opts.fetch(:auto_collect_timeout, 20)
|
49
|
+
host = options[:host]
|
50
|
+
port = options[:port]
|
51
|
+
backlog = options[:backlog]
|
52
|
+
@threshold = options[:threshold]
|
52
53
|
|
53
54
|
@threads = []
|
54
|
-
@thread_threshold = thread_threshold
|
55
55
|
@server = ::TCPServer.new(host, port)
|
56
|
-
raise "
|
56
|
+
raise "The server was unable to start properly." if @server.closed?
|
57
|
+
|
57
58
|
@server.listen(backlog)
|
58
59
|
@working = []
|
59
60
|
@listen_fds = [@server]
|
@@ -62,7 +63,7 @@ module Protobuf
|
|
62
63
|
while running?
|
63
64
|
log_debug { sign_message("Waiting for connections") }
|
64
65
|
|
65
|
-
if ready_cnxns = IO.select(@listen_fds, [], [],
|
66
|
+
if ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT)
|
66
67
|
cnxns = ready_cnxns.first
|
67
68
|
cnxns.each do |client|
|
68
69
|
case
|
@@ -8,13 +8,13 @@ module Protobuf
|
|
8
8
|
include ::Protobuf::Rpc::Zmq::Util
|
9
9
|
attr_reader :frontend, :backend, :poller, :context
|
10
10
|
|
11
|
-
##
|
11
|
+
##
|
12
12
|
# Constructor
|
13
13
|
#
|
14
|
-
def initialize(
|
14
|
+
def initialize(options = {})
|
15
15
|
@context = ::ZMQ::Context.new
|
16
|
-
@frontend = setup_frontend(
|
17
|
-
@backend = setup_backend(
|
16
|
+
@frontend = setup_frontend(options)
|
17
|
+
@backend = setup_backend(options)
|
18
18
|
@poller = setup_poller
|
19
19
|
end
|
20
20
|
|
@@ -52,27 +52,29 @@ module Protobuf
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def setup_backend(
|
56
|
-
dealer_options =
|
57
|
-
host = dealer_options
|
58
|
-
port = dealer_options
|
59
|
-
protocol = dealer_options.fetch(:protocol, "tcp")
|
55
|
+
def setup_backend(options = {})
|
56
|
+
dealer_options = options.merge(:port => options[:port] + 1)
|
57
|
+
host = dealer_options[:host]
|
58
|
+
port = dealer_options[:port]
|
60
59
|
|
61
60
|
zmq_backend = context.socket(::ZMQ::DEALER)
|
62
|
-
zmq_error_check(zmq_backend.bind(
|
61
|
+
zmq_error_check(zmq_backend.bind(bind_address(host, port)))
|
63
62
|
zmq_backend
|
64
63
|
end
|
65
64
|
|
66
|
-
def setup_frontend(
|
67
|
-
host =
|
68
|
-
port =
|
69
|
-
protocol = opts.fetch(:protocol, "tcp")
|
65
|
+
def setup_frontend(options = {})
|
66
|
+
host = options[:host]
|
67
|
+
port = options[:port]
|
70
68
|
|
71
69
|
zmq_frontend = context.socket(::ZMQ::ROUTER)
|
72
|
-
zmq_error_check(zmq_frontend.bind(
|
70
|
+
zmq_error_check(zmq_frontend.bind(bind_address(host, port)))
|
73
71
|
zmq_frontend
|
74
72
|
end
|
75
73
|
|
74
|
+
def bind_address(host, port)
|
75
|
+
"tcp://#{resolve_ip(host)}:#{port}"
|
76
|
+
end
|
77
|
+
|
76
78
|
def setup_poller
|
77
79
|
zmq_poller = ::ZMQ::Poller.new
|
78
80
|
zmq_poller.register(frontend, ::ZMQ::POLLIN)
|
@@ -11,12 +11,12 @@ module Protobuf
|
|
11
11
|
##
|
12
12
|
# Class Methods
|
13
13
|
#
|
14
|
-
def self.run(
|
14
|
+
def self.run(options = {})
|
15
15
|
log_debug { sign_message("initializing broker") }
|
16
|
-
@broker = ::Protobuf::Rpc::Zmq::Broker.new(
|
17
|
-
local_worker_threads =
|
16
|
+
@broker = ::Protobuf::Rpc::Zmq::Broker.new(options)
|
17
|
+
local_worker_threads = options[:threads]
|
18
18
|
|
19
|
-
worker_options =
|
19
|
+
worker_options = options.merge(:port => options[:port] + 1)
|
20
20
|
log_debug { sign_message("starting server workers") }
|
21
21
|
local_worker_threads.times do
|
22
22
|
@threads << Thread.new { ::Protobuf::Rpc::Zmq::Worker.new(worker_options).run }
|
@@ -11,15 +11,13 @@ module Protobuf
|
|
11
11
|
##
|
12
12
|
# Constructor
|
13
13
|
#
|
14
|
-
def initialize(
|
15
|
-
|
16
|
-
|
17
|
-
port = @options.fetch(:port) { 9400 }
|
18
|
-
protocol = @options.fetch(:protocol) { "tcp" }
|
14
|
+
def initialize(options = {})
|
15
|
+
host = options[:host]
|
16
|
+
port = options[:port]
|
19
17
|
|
20
18
|
@zmq_context = ::ZMQ::Context.new
|
21
19
|
@socket = @zmq_context.socket(::ZMQ::REP)
|
22
|
-
zmq_error_check(@socket.connect("
|
20
|
+
zmq_error_check(@socket.connect("tcp://#{resolve_ip(host)}:#{port}"))
|
23
21
|
|
24
22
|
@poller = ::ZMQ::Poller.new
|
25
23
|
@poller.register(@socket, ::ZMQ::POLLIN)
|
data/lib/protobuf/version.rb
CHANGED
data/spec/benchmark/tasks.rb
CHANGED
@@ -60,7 +60,6 @@ namespace :benchmark do
|
|
60
60
|
|
61
61
|
def sock_client_sock_server(number_tests, test_length, global_bench = nil)
|
62
62
|
load "protobuf/socket.rb"
|
63
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
64
63
|
EM.stop if EM.reactor_running?
|
65
64
|
|
66
65
|
StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server|
|
@@ -76,7 +75,6 @@ namespace :benchmark do
|
|
76
75
|
|
77
76
|
def sock_client_em_server(number_tests, test_length, global_bench = nil)
|
78
77
|
load "protobuf/socket.rb"
|
79
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
80
78
|
EM.stop if EM.reactor_running?
|
81
79
|
em_thread = Thread.new { EM.run }
|
82
80
|
Thread.pass until EM.reactor_running?
|
@@ -97,7 +95,6 @@ namespace :benchmark do
|
|
97
95
|
|
98
96
|
def zmq_client_zmq_server(number_tests, test_length, global_bench = nil)
|
99
97
|
load "protobuf/zmq.rb"
|
100
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
101
98
|
StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server|
|
102
99
|
client = ::Test::ResourceService.client(:port => 9399)
|
103
100
|
|
@@ -4,9 +4,8 @@ require 'spec/support/test/resource_service'
|
|
4
4
|
describe 'Functional Socket Client' do
|
5
5
|
before(:all) do
|
6
6
|
load "protobuf/socket.rb"
|
7
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
8
7
|
Thread.abort_on_exception = true
|
9
|
-
server = OpenStruct.new(:
|
8
|
+
server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
|
10
9
|
@server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) }
|
11
10
|
Thread.pass until Protobuf::Rpc::Socket::Server.running?
|
12
11
|
end
|
@@ -4,9 +4,8 @@ require 'spec/support/test/resource_service'
|
|
4
4
|
describe 'Functional ZMQ Client' do
|
5
5
|
before(:all) do
|
6
6
|
load "protobuf/zmq.rb"
|
7
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
8
7
|
Thread.abort_on_exception = true
|
9
|
-
server = OpenStruct.new(:
|
8
|
+
server = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100, :threads => 5)
|
10
9
|
@server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) }
|
11
10
|
Thread.pass until Protobuf::Rpc::Zmq::Server.running?
|
12
11
|
end
|
@@ -6,36 +6,27 @@ require 'protobuf/zmq'
|
|
6
6
|
describe ::Protobuf::Rpc::Connector do
|
7
7
|
|
8
8
|
describe '.connector_for_client(true)' do
|
9
|
-
|
9
|
+
subject { described_class.connector_for_client }
|
10
10
|
|
11
11
|
context 'Protobuf.connector_type is socket' do
|
12
|
-
|
13
|
-
|
14
|
-
described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket
|
15
|
-
end
|
12
|
+
before { ::Protobuf.connector_type = :socket }
|
13
|
+
it { should eq ::Protobuf::Rpc::Connectors::Socket }
|
16
14
|
end
|
17
15
|
|
18
16
|
context 'Protobuf.connector_type is not a known value' do
|
19
|
-
|
20
|
-
|
21
|
-
described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Socket
|
22
|
-
end
|
17
|
+
before { ::Protobuf.connector_type = :socket }
|
18
|
+
it { should eq ::Protobuf::Rpc::Connectors::Socket }
|
23
19
|
end
|
24
20
|
|
25
21
|
context 'Protobuf.connector_type is evented' do
|
26
|
-
|
27
|
-
|
28
|
-
described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::EventMachine
|
29
|
-
end
|
22
|
+
before { ::Protobuf.connector_type = :evented }
|
23
|
+
it { should eq ::Protobuf::Rpc::Connectors::EventMachine }
|
30
24
|
end
|
31
25
|
|
32
26
|
context 'Protobuf.connector_type is zmq' do
|
33
|
-
|
34
|
-
|
35
|
-
described_class.connector_for_client(true).should eq ::Protobuf::Rpc::Connectors::Zmq
|
36
|
-
end
|
27
|
+
before { ::Protobuf.connector_type = :zmq }
|
28
|
+
it { should eq ::Protobuf::Rpc::Connectors::Zmq }
|
37
29
|
end
|
38
|
-
|
39
30
|
end
|
40
31
|
|
41
32
|
end
|
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Protobuf::Rpc::Connectors::Base do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:options) do
|
6
6
|
{ :timeout => 60 }
|
7
7
|
end
|
8
8
|
|
9
|
-
subject { Protobuf::Rpc::Connectors::Base.new(
|
9
|
+
subject { Protobuf::Rpc::Connectors::Base.new(options) }
|
10
10
|
|
11
11
|
describe "#send_request" do
|
12
12
|
it "raising an error when 'send_request' is not overridden" do
|
@@ -14,14 +14,14 @@ describe Protobuf::Rpc::Connectors::Base do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "does not raise error when 'send_request' is overridden" do
|
17
|
-
new_sub = Class.new(subject.class){ def send_request; end }.new(
|
17
|
+
new_sub = Class.new(subject.class){ def send_request; end }.new(options)
|
18
18
|
expect{ new_sub.send_request }.to_not raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '.new' do
|
23
23
|
it 'assigns passed options and initializes success/failure callbacks' do
|
24
|
-
subject.options.should eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(
|
24
|
+
subject.options.should eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(options))
|
25
25
|
subject.success_cb.should be_nil
|
26
26
|
subject.failure_cb.should be_nil
|
27
27
|
end
|
@@ -5,14 +5,12 @@ require 'protobuf/evented'
|
|
5
5
|
require 'protobuf/socket'
|
6
6
|
|
7
7
|
describe Protobuf::Rpc::Socket::Server do
|
8
|
-
before(:each) do
|
9
|
-
load 'protobuf/socket.rb'
|
10
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
8
|
+
before(:each) do
|
9
|
+
load 'protobuf/socket.rb'
|
11
10
|
end
|
12
11
|
|
13
12
|
before(:all) do
|
14
|
-
load 'protobuf/socket.rb'
|
15
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
13
|
+
load 'protobuf/socket.rb'
|
16
14
|
Thread.abort_on_exception = true
|
17
15
|
server = OpenStruct.new(:server => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
|
18
16
|
@server_thread = Thread.new(server) { |s| Protobuf::Rpc::SocketRunner.run(s) }
|
@@ -1,15 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ::Protobuf::Rpc::Zmq::Broker do
|
4
|
-
before(:each) do
|
5
|
-
load 'protobuf/zmq.rb'
|
6
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
4
|
+
before(:each) do
|
5
|
+
load 'protobuf/zmq.rb'
|
7
6
|
end
|
8
7
|
|
9
8
|
after(:each) do
|
10
9
|
subject.teardown
|
11
10
|
end
|
12
11
|
|
12
|
+
subject do
|
13
|
+
described_class.new({ :host => '127.0.0.1', :port => 9399 })
|
14
|
+
end
|
15
|
+
|
13
16
|
it 'sets up a context' do
|
14
17
|
subject.context.should be_a(::ZMQ::Context)
|
15
18
|
end
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe ::Protobuf::Rpc::Zmq::Worker do
|
4
4
|
before(:each) do
|
5
5
|
load 'protobuf/zmq.rb'
|
6
|
-
::Protobuf::Rpc::Connector.connector_for_client(true)
|
7
6
|
end
|
8
7
|
|
9
8
|
after(:each) do
|
@@ -11,6 +10,10 @@ describe ::Protobuf::Rpc::Zmq::Worker do
|
|
11
10
|
subject.instance_variable_get(:@zmq_context).terminate
|
12
11
|
end
|
13
12
|
|
13
|
+
subject do
|
14
|
+
described_class.new({ :host => '127.0.0.1', :port => 9400 })
|
15
|
+
end
|
16
|
+
|
14
17
|
it 'sets the context' do
|
15
18
|
subject.instance_variable_get(:@zmq_context).should be_a(::ZMQ::Context)
|
16
19
|
end
|
data/spec/support/server.rb
CHANGED
@@ -37,12 +37,12 @@ class StubServer
|
|
37
37
|
|
38
38
|
attr_accessor :options
|
39
39
|
|
40
|
-
def initialize(
|
40
|
+
def initialize(options = {})
|
41
41
|
@running = true
|
42
42
|
@options = OpenStruct.new({ :host => "127.0.0.1",
|
43
43
|
:port => 9399,
|
44
44
|
:delay => 0,
|
45
|
-
:server => Protobuf::Rpc::Evented::Server }.merge(
|
45
|
+
:server => Protobuf::Rpc::Evented::Server }.merge(options))
|
46
46
|
|
47
47
|
start
|
48
48
|
yield self
|
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: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-06 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &2152100680 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2152100680
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: ffi
|
28
|
-
requirement: &
|
28
|
+
requirement: &2152099380 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2152099380
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: multi_json
|
39
|
-
requirement: &
|
39
|
+
requirement: &2152098400 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2152098400
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: thor
|
50
|
-
requirement: &
|
50
|
+
requirement: &2152097220 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2152097220
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: eventmachine
|
61
|
-
requirement: &
|
61
|
+
requirement: &2152095600 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2152095600
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: ffi-rzmq
|
72
|
-
requirement: &
|
72
|
+
requirement: &2152094240 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2152094240
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: perftools.rb
|
83
|
-
requirement: &
|
83
|
+
requirement: &2152088440 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2152088440
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: pry
|
94
|
-
requirement: &
|
94
|
+
requirement: &2152087100 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2152087100
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: pry-nav
|
105
|
-
requirement: &
|
105
|
+
requirement: &2152086180 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *2152086180
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: rake
|
116
|
-
requirement: &
|
116
|
+
requirement: &2152085220 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: '0'
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *2152085220
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rake-compiler
|
127
|
-
requirement: &
|
127
|
+
requirement: &2152083820 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ! '>='
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *2152083820
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: rspec
|
138
|
-
requirement: &
|
138
|
+
requirement: &2152082700 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ! '>='
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: '0'
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *2152082700
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: simplecov
|
149
|
-
requirement: &
|
149
|
+
requirement: &2152081360 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ! '>='
|
@@ -154,10 +154,10 @@ dependencies:
|
|
154
154
|
version: '0'
|
155
155
|
type: :development
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *2152081360
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: yard
|
160
|
-
requirement: &
|
160
|
+
requirement: &2152080320 !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
version: '0'
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
|
-
version_requirements: *
|
168
|
+
version_requirements: *2152080320
|
169
169
|
description: Google Protocol Buffers v2.4.1 Serialization and RPC implementation for
|
170
170
|
Ruby.
|
171
171
|
email:
|
@@ -446,7 +446,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
446
446
|
version: '0'
|
447
447
|
segments:
|
448
448
|
- 0
|
449
|
-
hash:
|
449
|
+
hash: 893090751339011969
|
450
450
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
451
451
|
none: false
|
452
452
|
requirements:
|
@@ -455,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
455
455
|
version: '0'
|
456
456
|
segments:
|
457
457
|
- 0
|
458
|
-
hash:
|
458
|
+
hash: 893090751339011969
|
459
459
|
requirements: []
|
460
460
|
rubyforge_project:
|
461
461
|
rubygems_version: 1.8.15
|