oleganza-emrpc 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +129 -0
- data/Rakefile +156 -0
- data/TODO +47 -0
- data/bin/emrpc +4 -0
- data/lib/emrpc.rb +15 -0
- data/lib/emrpc/archive/reference_savior.rb +48 -0
- data/lib/emrpc/archive/ring.rb +44 -0
- data/lib/emrpc/blocking_api.rb +3 -0
- data/lib/emrpc/blocking_api/method_proxy.rb +57 -0
- data/lib/emrpc/blocking_api/multithreaded_client.rb +52 -0
- data/lib/emrpc/blocking_api/singlethreaded_client.rb +68 -0
- data/lib/emrpc/client.rb +28 -0
- data/lib/emrpc/console.rb +32 -0
- data/lib/emrpc/evented_api.rb +14 -0
- data/lib/emrpc/evented_api/connection_mixin.rb +14 -0
- data/lib/emrpc/evented_api/debug_connection.rb +52 -0
- data/lib/emrpc/evented_api/debug_pid_callbacks.rb +39 -0
- data/lib/emrpc/evented_api/default_callbacks.rb +40 -0
- data/lib/emrpc/evented_api/evented_wrapper.rb +28 -0
- data/lib/emrpc/evented_api/local_connection.rb +48 -0
- data/lib/emrpc/evented_api/pid.rb +198 -0
- data/lib/emrpc/evented_api/protocol_mapper.rb +57 -0
- data/lib/emrpc/evented_api/reconnecting_pid.rb +105 -0
- data/lib/emrpc/evented_api/remote_connection.rb +73 -0
- data/lib/emrpc/evented_api/remote_pid.rb +38 -0
- data/lib/emrpc/evented_api/subscribable.rb +56 -0
- data/lib/emrpc/evented_api/timer.rb +23 -0
- data/lib/emrpc/protocols.rb +2 -0
- data/lib/emrpc/protocols/fast_message_protocol.rb +99 -0
- data/lib/emrpc/protocols/marshal_protocol.rb +33 -0
- data/lib/emrpc/server.rb +17 -0
- data/lib/emrpc/util.rb +7 -0
- data/lib/emrpc/util/blank_slate.rb +25 -0
- data/lib/emrpc/util/codec.rb +114 -0
- data/lib/emrpc/util/combine_modules.rb +11 -0
- data/lib/emrpc/util/em2rev.rb +48 -0
- data/lib/emrpc/util/em_start_stop_timeouts.rb +62 -0
- data/lib/emrpc/util/parsed_uri.rb +15 -0
- data/lib/emrpc/util/safe_run.rb +23 -0
- data/lib/emrpc/util/timers.rb +17 -0
- data/lib/emrpc/version.rb +3 -0
- data/spec/blocking_api/method_proxy_spec.rb +33 -0
- data/spec/blocking_api/multithreaded_client_spec.rb +52 -0
- data/spec/blocking_api/scenario_spec.rb +35 -0
- data/spec/blocking_api/singlethreaded_client_spec.rb +63 -0
- data/spec/blocking_api/spec_helper.rb +1 -0
- data/spec/blocking_api_test.rb +98 -0
- data/spec/evented_api/connection_mixin_spec.rb +34 -0
- data/spec/evented_api/default_callbacks_spec.rb +26 -0
- data/spec/evented_api/evented_wrapper_spec.rb +50 -0
- data/spec/evented_api/pid_spec.rb +194 -0
- data/spec/evented_api/reconnecting_pid_spec.rb +76 -0
- data/spec/evented_api/remote_connection_spec.rb +147 -0
- data/spec/evented_api/remote_pid_spec.rb +84 -0
- data/spec/evented_api/scenario_spec.rb +138 -0
- data/spec/evented_api/spec_helper.rb +10 -0
- data/spec/evented_api/subscribable_spec.rb +53 -0
- data/spec/server_spec.rb +7 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/util/blank_slate_spec.rb +7 -0
- data/spec/util/codec_spec.rb +183 -0
- data/spec/util/fast_message_protocol_spec.rb +60 -0
- data/spec/util/marshal_protocol_spec.rb +50 -0
- data/spec/util/parsed_uri_spec.rb +19 -0
- data/spec/util/spec_helper.rb +1 -0
- metadata +164 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe FastMessageProtocol do
|
4
|
+
before(:each) do
|
5
|
+
@peer_class = Class.new do
|
6
|
+
def initialize
|
7
|
+
post_init
|
8
|
+
end
|
9
|
+
def post_init
|
10
|
+
end
|
11
|
+
end
|
12
|
+
@oleganza = Class.new(@peer_class) do
|
13
|
+
include FastMessageProtocol
|
14
|
+
end
|
15
|
+
@yrashk = Class.new(@peer_class) do
|
16
|
+
include FastMessageProtocol
|
17
|
+
end
|
18
|
+
@oleganza.class_eval do
|
19
|
+
attr_accessor :messages
|
20
|
+
def post_init
|
21
|
+
@messages = []
|
22
|
+
super
|
23
|
+
end
|
24
|
+
def receive_message(msg)
|
25
|
+
@messages << msg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@yrashk.class_eval do
|
29
|
+
attr_accessor :peer
|
30
|
+
def post_init
|
31
|
+
@buffer = ""
|
32
|
+
super
|
33
|
+
end
|
34
|
+
def send_data(data)
|
35
|
+
@buffer << data
|
36
|
+
flush_buffer if @buffer.size > (rand(300) + 1)
|
37
|
+
end
|
38
|
+
def flush_buffer
|
39
|
+
@peer.receive_data(@buffer.dup)
|
40
|
+
@buffer = ""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should receive all messages" do
|
46
|
+
messages = Array.new(1000) {|i| (i*(rand(100)+1)).to_s*(1+rand(100)) }
|
47
|
+
oleg = @oleganza.new
|
48
|
+
yr = @yrashk.new
|
49
|
+
yr.peer = oleg
|
50
|
+
messages.each {|m| yr.send_message(m) }
|
51
|
+
yr.flush_buffer
|
52
|
+
|
53
|
+
oleg.messages.should == messages
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should handle protocol errors" do
|
57
|
+
pending "Add message size limit and specs!"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
def create_marshal_protocol_instance(interface)
|
7
|
+
mod = MarshalProtocol.new(interface)
|
8
|
+
|
9
|
+
spec_module = Module.new do
|
10
|
+
def send_message(data)
|
11
|
+
data
|
12
|
+
end
|
13
|
+
def receive_marshalled_message(data)
|
14
|
+
data
|
15
|
+
end
|
16
|
+
def rescue_marshal_error(e)
|
17
|
+
[:error, e]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Class.new do
|
22
|
+
include mod
|
23
|
+
include spec_module
|
24
|
+
end.new
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Generic MarshalProtocol", :shared => true do
|
28
|
+
it "should pass data in and out" do
|
29
|
+
encoded = @instance.send_marshalled_message(@msg)
|
30
|
+
decoded = @instance.receive_message(encoded)
|
31
|
+
decoded.should == @msg
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should report error when format is wrong" do
|
35
|
+
encoded = @instance.send_marshalled_message(@msg)
|
36
|
+
decoded = @instance.receive_message("blah-blah"+encoded)
|
37
|
+
decoded.first.should == :error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
[Marshal, JSON, YAML].each do |interface|
|
42
|
+
describe MarshalProtocol, "with #{interface}" do
|
43
|
+
before(:each) do
|
44
|
+
# FIXME: fixture containing 3.1415 may cause floating point issues.
|
45
|
+
@msg = ["Hello", {"a" => "b", "arr" => [true, false, nil]}, 1, 3.1415]
|
46
|
+
@instance = create_marshal_protocol_instance(interface)
|
47
|
+
end
|
48
|
+
it_should_behave_like "Generic MarshalProtocol"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe String, "#parsed_uri" do
|
4
|
+
before(:each) do
|
5
|
+
@str = "http://ya.ru/path?query"
|
6
|
+
@uri = @str.parsed_uri
|
7
|
+
end
|
8
|
+
it { @uri.should be_kind_of(::URI::Generic) }
|
9
|
+
it { @uri.should == URI.parse(@str) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ::URI::Generic, "#parsed_uri" do
|
13
|
+
before(:each) do
|
14
|
+
@str = "http://ya.ru/path?query"
|
15
|
+
@regular_uri = URI.parse(@str)
|
16
|
+
@uri = @regular_uri.parsed_uri
|
17
|
+
end
|
18
|
+
it { @uri.should equal(@regular_uri)}
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oleganza-emrpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.3"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Andreev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-03 00:00:00 -07:00
|
13
|
+
default_executable: emrpc
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rake
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: gem_console
|
44
|
+
version_requirement:
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
description: Efficient RPC library with evented and blocking APIs. In all ways better than DRb.
|
52
|
+
email: oleganza@gmail.com
|
53
|
+
executables:
|
54
|
+
- emrpc
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README
|
59
|
+
- TODO
|
60
|
+
- MIT-LICENSE
|
61
|
+
files:
|
62
|
+
- README
|
63
|
+
- Rakefile
|
64
|
+
- TODO
|
65
|
+
- MIT-LICENSE
|
66
|
+
- bin/emrpc
|
67
|
+
- spec/blocking_api
|
68
|
+
- spec/blocking_api/method_proxy_spec.rb
|
69
|
+
- spec/blocking_api/multithreaded_client_spec.rb
|
70
|
+
- spec/blocking_api/scenario_spec.rb
|
71
|
+
- spec/blocking_api/singlethreaded_client_spec.rb
|
72
|
+
- spec/blocking_api/spec_helper.rb
|
73
|
+
- spec/blocking_api_test.rb
|
74
|
+
- spec/evented_api
|
75
|
+
- spec/evented_api/connection_mixin_spec.rb
|
76
|
+
- spec/evented_api/default_callbacks_spec.rb
|
77
|
+
- spec/evented_api/evented_wrapper_spec.rb
|
78
|
+
- spec/evented_api/pid_spec.rb
|
79
|
+
- spec/evented_api/reconnecting_pid_spec.rb
|
80
|
+
- spec/evented_api/remote_connection_spec.rb
|
81
|
+
- spec/evented_api/remote_pid_spec.rb
|
82
|
+
- spec/evented_api/scenario_spec.rb
|
83
|
+
- spec/evented_api/spec_helper.rb
|
84
|
+
- spec/evented_api/subscribable_spec.rb
|
85
|
+
- spec/server_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/util
|
88
|
+
- spec/util/blank_slate_spec.rb
|
89
|
+
- spec/util/codec_spec.rb
|
90
|
+
- spec/util/fast_message_protocol_spec.rb
|
91
|
+
- spec/util/marshal_protocol_spec.rb
|
92
|
+
- spec/util/parsed_uri_spec.rb
|
93
|
+
- spec/util/spec_helper.rb
|
94
|
+
- lib/emrpc
|
95
|
+
- lib/emrpc/archive
|
96
|
+
- lib/emrpc/archive/reference_savior.rb
|
97
|
+
- lib/emrpc/archive/ring.rb
|
98
|
+
- lib/emrpc/blocking_api
|
99
|
+
- lib/emrpc/blocking_api/method_proxy.rb
|
100
|
+
- lib/emrpc/blocking_api/multithreaded_client.rb
|
101
|
+
- lib/emrpc/blocking_api/singlethreaded_client.rb
|
102
|
+
- lib/emrpc/blocking_api.rb
|
103
|
+
- lib/emrpc/client.rb
|
104
|
+
- lib/emrpc/console.rb
|
105
|
+
- lib/emrpc/evented_api
|
106
|
+
- lib/emrpc/evented_api/connection_mixin.rb
|
107
|
+
- lib/emrpc/evented_api/debug_connection.rb
|
108
|
+
- lib/emrpc/evented_api/debug_pid_callbacks.rb
|
109
|
+
- lib/emrpc/evented_api/default_callbacks.rb
|
110
|
+
- lib/emrpc/evented_api/evented_wrapper.rb
|
111
|
+
- lib/emrpc/evented_api/local_connection.rb
|
112
|
+
- lib/emrpc/evented_api/pid.rb
|
113
|
+
- lib/emrpc/evented_api/protocol_mapper.rb
|
114
|
+
- lib/emrpc/evented_api/reconnecting_pid.rb
|
115
|
+
- lib/emrpc/evented_api/remote_connection.rb
|
116
|
+
- lib/emrpc/evented_api/remote_pid.rb
|
117
|
+
- lib/emrpc/evented_api/subscribable.rb
|
118
|
+
- lib/emrpc/evented_api/timer.rb
|
119
|
+
- lib/emrpc/evented_api.rb
|
120
|
+
- lib/emrpc/protocols
|
121
|
+
- lib/emrpc/protocols/fast_message_protocol.rb
|
122
|
+
- lib/emrpc/protocols/marshal_protocol.rb
|
123
|
+
- lib/emrpc/protocols.rb
|
124
|
+
- lib/emrpc/server.rb
|
125
|
+
- lib/emrpc/util
|
126
|
+
- lib/emrpc/util/blank_slate.rb
|
127
|
+
- lib/emrpc/util/codec.rb
|
128
|
+
- lib/emrpc/util/combine_modules.rb
|
129
|
+
- lib/emrpc/util/em2rev.rb
|
130
|
+
- lib/emrpc/util/em_start_stop_timeouts.rb
|
131
|
+
- lib/emrpc/util/parsed_uri.rb
|
132
|
+
- lib/emrpc/util/safe_run.rb
|
133
|
+
- lib/emrpc/util/timers.rb
|
134
|
+
- lib/emrpc/util.rb
|
135
|
+
- lib/emrpc/version.rb
|
136
|
+
- lib/emrpc.rb
|
137
|
+
has_rdoc: true
|
138
|
+
homepage: http://oleganza.com/
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 1.8.4
|
149
|
+
version:
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: "0"
|
155
|
+
version:
|
156
|
+
requirements:
|
157
|
+
- You need to install the json (or json_pure), yaml, rack gems to use related features.
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.2.0
|
160
|
+
signing_key:
|
161
|
+
specification_version: 2
|
162
|
+
summary: Efficient RPC library with evented and blocking APIs. In all ways better than DRb.
|
163
|
+
test_files: []
|
164
|
+
|