skein 0.3.7 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +4 -1
- data/Gemfile.lock +49 -36
- data/LICENSE.md +1 -1
- data/README.md +9 -4
- data/RELEASES.md +2 -0
- data/VERSION +1 -1
- data/bin/skein +1 -1
- data/examples/echo +66 -0
- data/examples/echo-server +77 -0
- data/lib/skein/adapter.rb +3 -0
- data/lib/skein/client/publisher.rb +10 -2
- data/lib/skein/client/rpc.rb +78 -19
- data/lib/skein/client/subscriber.rb +27 -4
- data/lib/skein/client/worker.rb +221 -63
- data/lib/skein/client.rb +20 -11
- data/lib/skein/config.rb +3 -1
- data/lib/skein/connected.rb +88 -17
- data/lib/skein/context.rb +5 -2
- data/lib/skein/handler/async.rb +6 -2
- data/lib/skein/handler.rb +131 -20
- data/lib/skein/rabbitmq.rb +1 -0
- data/lib/skein/timeout_queue.rb +43 -0
- data/lib/skein.rb +18 -2
- data/skein.gemspec +21 -24
- data/test/helper.rb +29 -0
- data/test/unit/test_skein_client.rb +4 -1
- data/test/unit/test_skein_client_publisher.rb +1 -1
- data/test/unit/test_skein_client_rpc.rb +37 -0
- data/test/unit/test_skein_client_subscriber.rb +29 -12
- data/test/unit/test_skein_client_worker.rb +22 -9
- data/test/unit/test_skein_connected.rb +21 -0
- data/test/unit/test_skein_rpc_timeout.rb +19 -0
- data/test/unit/test_skein_worker.rb +4 -0
- metadata +41 -16
- data/lib/skein/rpc/base.rb +0 -23
- data/lib/skein/rpc/error.rb +0 -34
- data/lib/skein/rpc/notification.rb +0 -2
- data/lib/skein/rpc/request.rb +0 -62
- data/lib/skein/rpc/response.rb +0 -38
- data/lib/skein/rpc.rb +0 -24
- data/test/unit/test_skein_rpc_error.rb +0 -10
- data/test/unit/test_skein_rpc_request.rb +0 -93
data/lib/skein/rpc/response.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
class Skein::RPC::Response < Skein::RPC::Base
|
2
|
-
# == Properties ===========================================================
|
3
|
-
|
4
|
-
attr_accessor :result
|
5
|
-
attr_accessor :error
|
6
|
-
|
7
|
-
# == Instance Methods =====================================================
|
8
|
-
|
9
|
-
def initialize(content = nil)
|
10
|
-
case (content)
|
11
|
-
when String
|
12
|
-
data = Skein::Support.symbolize_keys(JSON.load(content))
|
13
|
-
|
14
|
-
assign_from_hash!(data)
|
15
|
-
when Hash
|
16
|
-
assign_from_hash!(content)
|
17
|
-
when nil
|
18
|
-
self.id = SecureRandom.uuid
|
19
|
-
else
|
20
|
-
raise Skein::RPC::InvalidPayload, 'Invalid payload type: %s' % content.class
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_h
|
25
|
-
{
|
26
|
-
method: self.method,
|
27
|
-
params: self.params,
|
28
|
-
id: self.id
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
protected
|
33
|
-
def assign_from_hash!(hash)
|
34
|
-
self.result = hash[:result]
|
35
|
-
self.error = hash[:error]
|
36
|
-
self.id = hash[:id]
|
37
|
-
end
|
38
|
-
end
|
data/lib/skein/rpc.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
class Skein::RPC
|
2
|
-
class Exception < ::RuntimeError
|
3
|
-
attr_accessor :request
|
4
|
-
|
5
|
-
def to_error
|
6
|
-
Skein::RPC::Error.new(
|
7
|
-
error: '[%s] %s' % [ self.class, self.to_s ],
|
8
|
-
id: self.request ? self.request.id : nil
|
9
|
-
)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class InvalidPayload < Exception
|
14
|
-
end
|
15
|
-
|
16
|
-
class InvalidMethod < Exception
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
require_relative './rpc/base'
|
21
|
-
require_relative './rpc/error'
|
22
|
-
require_relative './rpc/request'
|
23
|
-
require_relative './rpc/response'
|
24
|
-
require_relative './rpc/notification'
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require_relative '../helper'
|
2
|
-
|
3
|
-
class TestSkeinRPCRequest < Test::Unit::TestCase
|
4
|
-
def test_default
|
5
|
-
request = Skein::RPC::Request.new
|
6
|
-
|
7
|
-
assert request.id
|
8
|
-
assert request.id.match(/\A\h{8}\-\h{4}\-\h{4}\-\h{4}\-\h{12}\z/)
|
9
|
-
|
10
|
-
assert_equal nil, request.method
|
11
|
-
assert_equal nil, request.params
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_with_invalid_method_name
|
15
|
-
request = Skein::RPC::Request.new(
|
16
|
-
method: 'invalid name',
|
17
|
-
id: 'aa8304bd-5c4a-4b77-a1bf-87f90d59b3af'
|
18
|
-
)
|
19
|
-
|
20
|
-
rescue Skein::RPC::InvalidMethod => e
|
21
|
-
assert e
|
22
|
-
|
23
|
-
assert e.request.is_a?(Skein::RPC::Request)
|
24
|
-
assert_equal 'aa8304bd-5c4a-4b77-a1bf-87f90d59b3af', e.to_error.id
|
25
|
-
else
|
26
|
-
fail
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_with_no_method_name
|
30
|
-
request = Skein::RPC::Request.new(
|
31
|
-
method: nil,
|
32
|
-
id: 'aa8304bd-5c4a-4b77-a1bf-87f90d59b3af'
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_with_single_param
|
37
|
-
request = Skein::RPC::Request.new(
|
38
|
-
method: 'single_param',
|
39
|
-
params: 'single'
|
40
|
-
)
|
41
|
-
|
42
|
-
assert_equal %w[ single ], request.params
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_from_json_string
|
46
|
-
raw = {
|
47
|
-
method: 'test_method',
|
48
|
-
params: nil,
|
49
|
-
id: 'e0b6cffa-8040-4c44-bc11-7fc3d8f4662c'
|
50
|
-
}
|
51
|
-
|
52
|
-
json = JSON.dump(raw)
|
53
|
-
|
54
|
-
request = Skein::RPC::Request.new(json)
|
55
|
-
|
56
|
-
assert_equal 'test_method', request.method
|
57
|
-
assert_equal nil, request.params
|
58
|
-
assert_equal 'e0b6cffa-8040-4c44-bc11-7fc3d8f4662c', request.id
|
59
|
-
|
60
|
-
assert_equal raw, request.to_h
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_from_hash
|
64
|
-
raw = {
|
65
|
-
method: 'test_method',
|
66
|
-
params: nil,
|
67
|
-
id: 'e0b6cffa-8040-4c44-bc11-7fc3d8f4662c'
|
68
|
-
}
|
69
|
-
|
70
|
-
request = Skein::RPC::Request.new(raw)
|
71
|
-
|
72
|
-
assert_equal 'test_method', request.method
|
73
|
-
assert_equal nil, request.params
|
74
|
-
assert_equal 'e0b6cffa-8040-4c44-bc11-7fc3d8f4662c', request.id
|
75
|
-
|
76
|
-
assert_equal raw, request.to_h
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_to_response_result
|
80
|
-
request = Skein::RPC::Request.new(
|
81
|
-
method: 'test_method',
|
82
|
-
params: 'test',
|
83
|
-
id: 'd8b625f1-5e0b-4bcf-bf6e-569e9edc634d'
|
84
|
-
)
|
85
|
-
|
86
|
-
response = request.response(
|
87
|
-
result: %w[ result ]
|
88
|
-
)
|
89
|
-
|
90
|
-
assert_equal request.id, response.id
|
91
|
-
assert_equal %w[ result ], response.result
|
92
|
-
end
|
93
|
-
end
|