combi 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e83ce25285ff2714f2e21113cecb746367cfc6fe
4
- data.tar.gz: ca74535ae551fb435cc972790c7bbe0030745ffe
3
+ metadata.gz: 38eced61f795b66ed4f2eafe663e8dd5a204b99a
4
+ data.tar.gz: e0793e82d4b75ba93ddc5a835a9bea71d1453117
5
5
  SHA512:
6
- metadata.gz: 9654c9586db5baaf388d891cf640f6481103aa5dfe85a3237be894284c2c50bfba4213586f6699447e52ec64c944741c17c231f17685af4e1a66cf221dffec6c
7
- data.tar.gz: b389cf59a5ef1e0c37b4d2a907c4ff68292f29e153ba352431a26e01e58052e61ee81061e83621994cf1df79c8bb3541989e9cb653883ad6279c23b2c795ff1a
6
+ metadata.gz: c8bddb984ae14b2c28329dc152873cd580dd70e3bc13a641fb1da673d0edf6c2835b59d52ec87acc2552cab6124e79f33a4be8829eecba68e05ce6667b90e124
7
+ data.tar.gz: 756143cca67900ca14a5c038ab14eda751ebda96a68c956634c8b5fcf3885f396bd6f88ec9e9b00ce7f4c2cbf8978344748079cf2b4145e9cac241f7fa4f5fff
@@ -54,7 +54,11 @@ module Combi
54
54
  kind = message['kind']
55
55
  if service_instance.respond_to? kind
56
56
  message['payload'] ||= {}
57
- response = service_instance.send(kind, message['payload'])
57
+ begin
58
+ response = service_instance.send(kind, message['payload'])
59
+ rescue Exception => e
60
+ response = {error: true, message: e.message}
61
+ end
58
62
  {result: 'ok', response: response}
59
63
  end
60
64
  end
@@ -26,9 +26,10 @@ module Combi
26
26
  rescue Timeout::Error => e
27
27
  log "ERROR"
28
28
  waiter.fail RuntimeError.new(Timeout::Error)
29
- rescue e
29
+ rescue Exception => e
30
30
  log "other ERROR"
31
31
  log e.inspect
32
+ waiter.fail({'error' => true, 'message' => e.message})
32
33
  end
33
34
  waiter
34
35
  end
@@ -69,17 +69,21 @@ module Combi
69
69
  return
70
70
  end
71
71
  log "generating response for #{service_instance.class}#{service_instance.actions.inspect}.#{kind} #{payload.inspect}"
72
- response = service_instance.send(kind, payload)
72
+ begin
73
+ response = service_instance.send(kind, payload)
74
+ rescue Exception => e
75
+ response = {error: true, message: e.message}
76
+ end
73
77
 
74
78
  if response.respond_to? :succeed
75
79
  log "response is deferred"
76
80
  response.callback do |service_response|
77
81
  log "responding with deferred answer: #{service_response.inspect}"
78
- queue_service.respond(service_response, delivery_info)
82
+ queue_service.respond(service_response.to_json, delivery_info)
79
83
  end
80
84
  else
81
85
  log "responding with inmediate answer: #{response.inspect}"
82
- queue_service.respond(response, delivery_info) unless response.nil?
86
+ queue_service.respond(response.to_json, delivery_info) unless response.nil?
83
87
  end
84
88
  end
85
89
 
@@ -170,17 +170,21 @@ module Combi
170
170
  kind = message['kind']
171
171
  payload = message['payload'] || {}
172
172
  payload['session'] = session
173
- response = invoke_service(service_name, kind, payload)
173
+ begin
174
+ response = invoke_service(service_name, kind, payload)
175
+ rescue Exception => e
176
+ response = {error: true, message: e.message}
177
+ end
174
178
 
175
179
  msg = {result: 'ok', correlation_id: message['correlation_id']}
176
180
 
177
181
  if response.respond_to? :succeed
178
182
  response.callback do |service_response|
179
- msg[:response] = service_response
183
+ msg[:response] = service_response.to_json
180
184
  ws.send(msg.to_json)
181
185
  end
182
186
  else
183
- msg[:response] = response
187
+ msg[:response] = response.to_json
184
188
  ws.send(msg.to_json)
185
189
  end
186
190
  end
@@ -49,7 +49,6 @@ module Combi
49
49
  end
50
50
 
51
51
  def publish(*args, &block)
52
- args[0] = args[0].to_json unless args[0].is_a? String
53
52
  @exchange.publish *args do
54
53
  log "Sent to network drivers: #{args.inspect}"
55
54
  block.call if block_given?
@@ -95,7 +94,7 @@ module Combi
95
94
  payload: message,
96
95
  options: {}
97
96
  }
98
- publish(request, options)
97
+ publish(request.to_json, options)
99
98
  end
100
99
 
101
100
  end
@@ -14,7 +14,7 @@ module Combi
14
14
  correlation_id = response['correlation_id']
15
15
  waiter = @waiters[correlation_id]
16
16
  response = response['response']
17
- waiter.succeed(response)
17
+ waiter.succeed(JSON.parse response)
18
18
  @waiters.delete correlation_id
19
19
  end
20
20
  end
data/lib/combi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Combi
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -20,6 +20,24 @@ shared_examples_for "standard_bus" do
20
20
  end
21
21
  end
22
22
 
23
+ Given(:echo_service) do
24
+ Module.new do
25
+ def actions; [:echo_this]; end
26
+ def do_it(params)
27
+ params['data']
28
+ end
29
+ end
30
+ end
31
+
32
+ Given(:broken_service) do
33
+ Module.new do
34
+ def actions; [:shout_error]; end
35
+ def do_it(params)
36
+ raise params['message']
37
+ end
38
+ end
39
+ end
40
+
23
41
  Given(:finalize) do
24
42
  provider.stop!
25
43
  consumer.stop!
@@ -59,4 +77,78 @@ shared_examples_for "standard_bus" do
59
77
  end
60
78
  end
61
79
  end
80
+
81
+ context 'return the same data type returned by service' do
82
+ Given(:result_container) { {} }
83
+ Given(:params) { { data: data } }
84
+ When(:service) { provider.add_service echo_service }
85
+ When('service is called') do
86
+ em do
87
+ prepare
88
+ EM.synchrony do
89
+ result_container[:result] = EM::Synchrony.sync consumer.request(:echo_this, :do_it, params)
90
+ done
91
+ finalize
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'for string' do
97
+ Given(:data) { "a simple string" }
98
+ Then { result_container[:result].should eq data}
99
+ end
100
+
101
+ context 'for numbers' do
102
+ Given(:data) { 237.324 }
103
+ Then { result_container[:result].should eq data}
104
+ end
105
+
106
+ context 'for arrays' do
107
+ Given(:data) { [1, 2, 3.0, "4", "cinco"]}
108
+ Then { result_container[:result].should eq data}
109
+ end
110
+
111
+ context 'for symbols always return a string' do
112
+ Given(:data) { :some_symbol }
113
+ Then { result_container[:result].should eq data.to_s}
114
+ end
115
+
116
+ context 'for maps' do
117
+ Given(:data) { {'a' => 1, 'b' => 'dos'} }
118
+ Then { result_container[:result].should eq data}
119
+ end
120
+
121
+ context 'for objects returns their json version' do
122
+ Given(:custom_json) { {val: 'value'} }
123
+ Given(:custom_class) do
124
+ Class.new do
125
+ def initialize(custom_json)
126
+ @custom_json = custom_json
127
+ end
128
+ def to_json
129
+ @custom_json
130
+ end
131
+ end
132
+ end
133
+ Given(:data) { custom_class.new(custom_json).to_json}
134
+ Then { result_container[:result].should eq JSON.parse(custom_json.to_json)}
135
+ end
136
+ end
137
+
138
+ context 'return something when service raise an error' do
139
+ Given(:error_message) { 'service is broken' }
140
+ When(:service) { provider.add_service broken_service }
141
+ Then do
142
+ em do
143
+ prepare
144
+ EM.synchrony do
145
+ service_result = EM::Synchrony.sync consumer.request(:shout_error, :do_it, {message: error_message}, { timeout: 0.1 })
146
+ service_result['error'].should be_true
147
+ service_result['message'].should eq error_message
148
+ done
149
+ finalize
150
+ end
151
+ end
152
+ end
153
+ end
62
154
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - German Del Zotto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-14 00:00:00.000000000 Z
12
+ date: 2014-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
@@ -196,8 +196,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.2.2
199
+ rubygems_version: 2.2.0
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Mini Bus for microservices
203
203
  test_files: []
204
+ has_rdoc: