skein 0.3.7 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +4 -1
  3. data/Gemfile.lock +49 -36
  4. data/LICENSE.md +1 -1
  5. data/README.md +9 -4
  6. data/RELEASES.md +2 -0
  7. data/VERSION +1 -1
  8. data/bin/skein +1 -1
  9. data/examples/echo +66 -0
  10. data/examples/echo-server +77 -0
  11. data/lib/skein/adapter.rb +3 -0
  12. data/lib/skein/client/publisher.rb +10 -2
  13. data/lib/skein/client/rpc.rb +78 -19
  14. data/lib/skein/client/subscriber.rb +27 -4
  15. data/lib/skein/client/worker.rb +221 -63
  16. data/lib/skein/client.rb +20 -11
  17. data/lib/skein/config.rb +3 -1
  18. data/lib/skein/connected.rb +88 -17
  19. data/lib/skein/context.rb +5 -2
  20. data/lib/skein/handler/async.rb +6 -2
  21. data/lib/skein/handler.rb +131 -20
  22. data/lib/skein/rabbitmq.rb +1 -0
  23. data/lib/skein/timeout_queue.rb +43 -0
  24. data/lib/skein.rb +18 -2
  25. data/skein.gemspec +21 -24
  26. data/test/helper.rb +29 -0
  27. data/test/unit/test_skein_client.rb +4 -1
  28. data/test/unit/test_skein_client_publisher.rb +1 -1
  29. data/test/unit/test_skein_client_rpc.rb +37 -0
  30. data/test/unit/test_skein_client_subscriber.rb +29 -12
  31. data/test/unit/test_skein_client_worker.rb +22 -9
  32. data/test/unit/test_skein_connected.rb +21 -0
  33. data/test/unit/test_skein_rpc_timeout.rb +19 -0
  34. data/test/unit/test_skein_worker.rb +4 -0
  35. metadata +41 -16
  36. data/lib/skein/rpc/base.rb +0 -23
  37. data/lib/skein/rpc/error.rb +0 -34
  38. data/lib/skein/rpc/notification.rb +0 -2
  39. data/lib/skein/rpc/request.rb +0 -62
  40. data/lib/skein/rpc/response.rb +0 -38
  41. data/lib/skein/rpc.rb +0 -24
  42. data/test/unit/test_skein_rpc_error.rb +0 -10
  43. data/test/unit/test_skein_rpc_request.rb +0 -93
@@ -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,10 +0,0 @@
1
- require_relative '../helper'
2
-
3
- class TestSkeinRPCError < Test::Unit::TestCase
4
- def test_default
5
- error = Skein::RPC::Error.new
6
-
7
- assert_equal nil, error.id
8
- assert_equal nil, error.error
9
- end
10
- end
@@ -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