euston 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/euston.gemspec +7 -6
- data/lib/euston/aggregate_root.rb +19 -21
- data/lib/euston/event_handler.rb +1 -1
- data/lib/euston/version.rb +1 -1
- data/spec/aggregate_root_samples.rb +1 -0
- data/spec/aggregate_root_spec.rb +37 -11
- data/spec/spec_helper.rb +2 -0
- metadata +33 -16
data/Rakefile
CHANGED
@@ -65,7 +65,7 @@ end
|
|
65
65
|
#
|
66
66
|
#############################################################################
|
67
67
|
|
68
|
-
default_rspec_opts = %w[--colour --format Fuubar]
|
68
|
+
default_rspec_opts = %w[--colour --tty -b --format Fuubar]
|
69
69
|
|
70
70
|
desc "Run all examples"
|
71
71
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
data/euston.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'euston'
|
3
|
-
s.version = '1.2.
|
4
|
-
s.date = '2012-02-
|
3
|
+
s.version = '1.2.9'
|
4
|
+
s.date = '2012-02-28'
|
5
5
|
s.platform = RUBY_PLATFORM.to_s == 'java' ? 'java' : Gem::Platform::RUBY
|
6
6
|
s.authors = ['Lee Henson', 'Guy Boertje']
|
7
7
|
s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
|
@@ -46,8 +46,9 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_dependency 'activemodel', '~> 3.1.0'
|
47
47
|
s.add_dependency 'activesupport', '~> 3.1.0'
|
48
48
|
|
49
|
-
s.add_development_dependency '
|
50
|
-
s.add_development_dependency '
|
51
|
-
s.add_development_dependency '
|
52
|
-
s.add_development_dependency '
|
49
|
+
s.add_development_dependency 'awesome_print', '~> 1.0.2'
|
50
|
+
s.add_development_dependency 'fuubar', '~> 1.0.0'
|
51
|
+
s.add_development_dependency 'rake', '~> 0.9.2'
|
52
|
+
s.add_development_dependency 'rspec', '~> 2.6.0'
|
53
|
+
s.add_development_dependency 'uuid', '~> 2.3.0'
|
53
54
|
end
|
@@ -44,6 +44,10 @@ module Euston
|
|
44
44
|
@uncommitted_events ||= []
|
45
45
|
end
|
46
46
|
|
47
|
+
def uncommitted_headers
|
48
|
+
@uncommitted_headers ||= {}
|
49
|
+
end
|
50
|
+
|
47
51
|
def consume_command headers, command
|
48
52
|
consume_message headers, command, :command, Euston::CommandHeaders, :send_command_to_method
|
49
53
|
end
|
@@ -52,16 +56,6 @@ module Euston
|
|
52
56
|
consume_message headers, event, :event_subscription, Euston::EventHeaders, :send_event_subscription_to_method
|
53
57
|
end
|
54
58
|
|
55
|
-
def replay_event headers, event
|
56
|
-
headers = Euston::EventHeaders.from_hash(headers) if headers.is_a?(Hash)
|
57
|
-
|
58
|
-
source_message = headers.source_message
|
59
|
-
committed_messages << source_message[:headers][:id] unless source_message.nil?
|
60
|
-
|
61
|
-
send_event_to_method headers, event
|
62
|
-
@initial_version = initial_version + 1
|
63
|
-
end
|
64
|
-
|
65
59
|
def take_snapshot
|
66
60
|
methods = self.class.instance_methods
|
67
61
|
regex = self.class.take_snapshot_regexp
|
@@ -88,11 +82,6 @@ module Euston
|
|
88
82
|
:version => version,
|
89
83
|
:timestamp => Time.now.to_f
|
90
84
|
|
91
|
-
unless @current_message_headers.nil?
|
92
|
-
event.headers[@current_message_type] = { :headers => @current_message_headers.to_hash,
|
93
|
-
:body => @current_message_body }
|
94
|
-
end
|
95
|
-
|
96
85
|
send_event_to_method Euston::EventHeaders.from_hash(event.headers), event.body
|
97
86
|
uncommitted_events << event
|
98
87
|
end
|
@@ -118,6 +107,10 @@ module Euston
|
|
118
107
|
|
119
108
|
raise "This aggregate cannot apply a historical event stream because it is not empty." unless uncommitted_events.empty? && initial_version == 0
|
120
109
|
|
110
|
+
unless stream.committed_headers[:source_message].nil?
|
111
|
+
committed_messages << stream.committed_headers[:source_message][:headers][:id]
|
112
|
+
end
|
113
|
+
|
121
114
|
events.each_with_index do |event, i|
|
122
115
|
replay_event event.headers, event.body
|
123
116
|
end
|
@@ -130,6 +123,12 @@ module Euston
|
|
130
123
|
uncommitted_commands << command
|
131
124
|
end
|
132
125
|
|
126
|
+
def replay_event headers, event
|
127
|
+
headers = Euston::EventHeaders.from_hash(headers) if headers.is_a?(Hash)
|
128
|
+
send_event_to_method headers, event
|
129
|
+
@initial_version = initial_version + 1
|
130
|
+
end
|
131
|
+
|
133
132
|
def send_command_to_method headers, command
|
134
133
|
deliver_message headers, command, :consumes_method_name, 'a command', "a 'consumes' block"
|
135
134
|
end
|
@@ -148,10 +147,9 @@ module Euston
|
|
148
147
|
headers = headers_type.from_hash(headers) if headers.is_a?(Hash)
|
149
148
|
|
150
149
|
unless committed_messages.include? headers.id
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
uncommitted_headers[:source_message_type] = message_type
|
151
|
+
uncommitted_headers[:source_message] = { headers: headers.to_hash, body: body }
|
152
|
+
|
155
153
|
self.send send_method, headers, body
|
156
154
|
end
|
157
155
|
|
@@ -164,9 +162,9 @@ module Euston
|
|
164
162
|
@log.debug "Calling #{name} with: #{message.inspect}"
|
165
163
|
m = method(name)
|
166
164
|
case m.arity
|
167
|
-
when 2, -2
|
165
|
+
when 2, -1, -2
|
168
166
|
m.call OpenStruct.new(headers.to_hash).freeze, OpenStruct.new(message).freeze
|
169
|
-
when 1
|
167
|
+
when 1
|
170
168
|
m.call OpenStruct.new(message).freeze
|
171
169
|
else
|
172
170
|
m.call
|
data/lib/euston/event_handler.rb
CHANGED
data/lib/euston/version.rb
CHANGED
data/spec/aggregate_root_spec.rb
CHANGED
@@ -2,21 +2,47 @@ require File.expand_path("../spec_helper", __FILE__)
|
|
2
2
|
|
3
3
|
module Euston
|
4
4
|
describe 'aggregate root' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
let(:aggregate) { Sample::Widget.new }
|
6
|
+
let(:command_headers) { CommandHeaders.new id: Euston.uuid.generate, type: 'create_widget', version: 1 }
|
7
|
+
let(:command_body) { { :id => Euston.uuid.generate } }
|
8
|
+
|
9
|
+
before do
|
10
|
+
aggregate.consume_command command_headers, command_body
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { aggregate }
|
14
|
+
|
15
|
+
context 'commmand consumption' do
|
16
|
+
its(:uncommitted_events) { should have(1).item }
|
17
|
+
|
18
|
+
describe 'the uncommitted headers' do
|
19
|
+
subject { aggregate.uncommitted_headers }
|
20
|
+
|
21
|
+
its([:source_message_type]) { should == :command }
|
10
22
|
|
11
|
-
|
12
|
-
|
13
|
-
aggregate.uncommitted_events.should have(1).item
|
23
|
+
describe 'the source message' do
|
24
|
+
subject { aggregate.uncommitted_headers[:source_message] }
|
14
25
|
|
15
|
-
|
26
|
+
its([:headers]) { should == command_headers }
|
27
|
+
its([:body]) { should == command_body }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
16
31
|
|
17
|
-
|
18
|
-
|
32
|
+
context 'duplicate command consumption' do
|
33
|
+
subject do
|
34
|
+
stream = OpenStruct.new.tap do |s|
|
35
|
+
s.committed_headers = { source_message_type: :command,
|
36
|
+
source_message: { headers: command_headers, body: command_body } }
|
37
|
+
s.committed_events = aggregate.uncommitted_events
|
38
|
+
end
|
39
|
+
|
40
|
+
aggregate2 = Sample::Widget.hydrate stream
|
41
|
+
aggregate2.consume_command command_headers, command_body
|
42
|
+
aggregate2
|
19
43
|
end
|
44
|
+
|
45
|
+
its(:uncommitted_events) { should have(0).items }
|
20
46
|
end
|
21
47
|
end
|
22
48
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: euston
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.9
|
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-02-
|
13
|
+
date: 2012-02-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70218912203040 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70218912203040
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &70218912202480 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,21 +33,32 @@ dependencies:
|
|
33
33
|
version: 3.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70218912202480
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: awesome_print
|
39
|
+
requirement: &70218912202000 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.2
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70218912202000
|
37
48
|
- !ruby/object:Gem::Dependency
|
38
49
|
name: fuubar
|
39
|
-
requirement: &
|
50
|
+
requirement: &70218912201500 !ruby/object:Gem::Requirement
|
40
51
|
none: false
|
41
52
|
requirements:
|
42
53
|
- - ~>
|
43
54
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
55
|
+
version: 1.0.0
|
45
56
|
type: :development
|
46
57
|
prerelease: false
|
47
|
-
version_requirements: *
|
58
|
+
version_requirements: *70218912201500
|
48
59
|
- !ruby/object:Gem::Dependency
|
49
60
|
name: rake
|
50
|
-
requirement: &
|
61
|
+
requirement: &70218912200960 !ruby/object:Gem::Requirement
|
51
62
|
none: false
|
52
63
|
requirements:
|
53
64
|
- - ~>
|
@@ -55,10 +66,10 @@ dependencies:
|
|
55
66
|
version: 0.9.2
|
56
67
|
type: :development
|
57
68
|
prerelease: false
|
58
|
-
version_requirements: *
|
69
|
+
version_requirements: *70218912200960
|
59
70
|
- !ruby/object:Gem::Dependency
|
60
71
|
name: rspec
|
61
|
-
requirement: &
|
72
|
+
requirement: &70218912200420 !ruby/object:Gem::Requirement
|
62
73
|
none: false
|
63
74
|
requirements:
|
64
75
|
- - ~>
|
@@ -66,10 +77,10 @@ dependencies:
|
|
66
77
|
version: 2.6.0
|
67
78
|
type: :development
|
68
79
|
prerelease: false
|
69
|
-
version_requirements: *
|
80
|
+
version_requirements: *70218912200420
|
70
81
|
- !ruby/object:Gem::Dependency
|
71
82
|
name: uuid
|
72
|
-
requirement: &
|
83
|
+
requirement: &70218912199880 !ruby/object:Gem::Requirement
|
73
84
|
none: false
|
74
85
|
requirements:
|
75
86
|
- - ~>
|
@@ -77,7 +88,7 @@ dependencies:
|
|
77
88
|
version: 2.3.0
|
78
89
|
type: :development
|
79
90
|
prerelease: false
|
80
|
-
version_requirements: *
|
91
|
+
version_requirements: *70218912199880
|
81
92
|
description: ''
|
82
93
|
email:
|
83
94
|
- lee.m.henson@gmail.com
|
@@ -124,15 +135,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
135
|
- - ! '>='
|
125
136
|
- !ruby/object:Gem::Version
|
126
137
|
version: '0'
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
hash: -818260274026684501
|
127
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
142
|
none: false
|
129
143
|
requirements:
|
130
144
|
- - ! '>='
|
131
145
|
- !ruby/object:Gem::Version
|
132
146
|
version: '0'
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
hash: -818260274026684501
|
133
150
|
requirements: []
|
134
151
|
rubyforge_project:
|
135
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.17
|
136
153
|
signing_key:
|
137
154
|
specification_version: 3
|
138
155
|
summary: Cqrs tooling.
|