euston 1.2.8-java → 1.2.9-java

Sign up to get free protection for your applications and to get access to all the features.
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|
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'euston'
3
- s.version = '1.2.8'
4
- s.date = '2012-02-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 'fuubar', '~> 0.0.0'
50
- s.add_development_dependency 'rake', '~> 0.9.2'
51
- s.add_development_dependency 'rspec', '~> 2.6.0'
52
- s.add_development_dependency 'uuid', '~> 2.3.0'
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
- @current_message_type = message_type
152
- @current_message_headers = headers
153
- @current_message_body = body
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, -1
167
+ when 1
170
168
  m.call OpenStruct.new(message).freeze
171
169
  else
172
170
  m.call
@@ -24,7 +24,7 @@ module Euston
24
24
  method_name = event_handler_method_name type, version
25
25
  define_method method_name, &consumer
26
26
  new_method = instance_method method_name
27
-
27
+
28
28
  define_method method_name do |*args|
29
29
  new_method.bind(self).call *args
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Euston
2
- VERSION = "1.2.8"
2
+ VERSION = "1.2.9"
3
3
  end
@@ -44,6 +44,7 @@ module Euston
44
44
  apply_event :product_access_logged, 1, :product_id => command.product_id,
45
45
  :access_count => @access_count + 1
46
46
  end
47
+
47
48
  applies :product_created, 1 do |event|
48
49
  @access_count = 0
49
50
  end
@@ -2,21 +2,47 @@ require File.expand_path("../spec_helper", __FILE__)
2
2
 
3
3
  module Euston
4
4
  describe 'aggregate root' do
5
- context 'duplicate command consumption' do
6
- let(:aggregate) { Sample::Widget.new }
7
- let(:aggregate2) { Sample::Widget.new }
8
- let(:command) { { :headers => CommandHeaders.new(id: Euston.uuid.generate, type: 'create_widget', version: 1),
9
- :body => { :id => Euston.uuid.generate } } }
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
- it 'does not handle the same command twice' do
12
- aggregate.consume_command command[:headers], command[:body]
13
- aggregate.uncommitted_events.should have(1).item
23
+ describe 'the source message' do
24
+ subject { aggregate.uncommitted_headers[:source_message] }
14
25
 
15
- aggregate.uncommitted_events.each { |e| aggregate2.replay_event e.headers, e.body }
26
+ its([:headers]) { should == command_headers }
27
+ its([:body]) { should == command_body }
28
+ end
29
+ end
30
+ end
16
31
 
17
- aggregate2.consume_command command[:headers], command[:body]
18
- aggregate2.uncommitted_events.should have(0).items
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
@@ -1,3 +1,5 @@
1
+ require 'ap'
2
+ require 'ostruct'
1
3
  require 'euston'
2
4
  require 'aggregate_root_samples'
3
5
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: euston
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.8
5
+ version: 1.2.9
6
6
  platform: java
7
7
  authors:
8
8
  - Lee Henson
@@ -10,72 +10,83 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-02-02 00:00:00.000000000Z
13
+ date: 2012-02-28 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- version_requirements: &3336 !ruby/object:Gem::Requirement
17
+ version_requirements: &3406 !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: 3.1.0
22
22
  none: false
23
- requirement: *3336
23
+ requirement: *3406
24
24
  prerelease: false
25
25
  type: :runtime
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- version_requirements: &3354 !ruby/object:Gem::Requirement
28
+ version_requirements: &3424 !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.1.0
33
33
  none: false
34
- requirement: *3354
34
+ requirement: *3424
35
35
  prerelease: false
36
36
  type: :runtime
37
+ - !ruby/object:Gem::Dependency
38
+ name: awesome_print
39
+ version_requirements: &3440 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.2
44
+ none: false
45
+ requirement: *3440
46
+ prerelease: false
47
+ type: :development
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: fuubar
39
- version_requirements: &3370 !ruby/object:Gem::Requirement
50
+ version_requirements: &3458 !ruby/object:Gem::Requirement
40
51
  requirements:
41
52
  - - ~>
42
53
  - !ruby/object:Gem::Version
43
- version: 0.0.0
54
+ version: 1.0.0
44
55
  none: false
45
- requirement: *3370
56
+ requirement: *3458
46
57
  prerelease: false
47
58
  type: :development
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: rake
50
- version_requirements: &3388 !ruby/object:Gem::Requirement
61
+ version_requirements: &3474 !ruby/object:Gem::Requirement
51
62
  requirements:
52
63
  - - ~>
53
64
  - !ruby/object:Gem::Version
54
65
  version: 0.9.2
55
66
  none: false
56
- requirement: *3388
67
+ requirement: *3474
57
68
  prerelease: false
58
69
  type: :development
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: rspec
61
- version_requirements: &3404 !ruby/object:Gem::Requirement
72
+ version_requirements: &3490 !ruby/object:Gem::Requirement
62
73
  requirements:
63
74
  - - ~>
64
75
  - !ruby/object:Gem::Version
65
76
  version: 2.6.0
66
77
  none: false
67
- requirement: *3404
78
+ requirement: *3490
68
79
  prerelease: false
69
80
  type: :development
70
81
  - !ruby/object:Gem::Dependency
71
82
  name: uuid
72
- version_requirements: &3420 !ruby/object:Gem::Requirement
83
+ version_requirements: &3506 !ruby/object:Gem::Requirement
73
84
  requirements:
74
85
  - - ~>
75
86
  - !ruby/object:Gem::Version
76
87
  version: 2.3.0
77
88
  none: false
78
- requirement: *3420
89
+ requirement: *3506
79
90
  prerelease: false
80
91
  type: :development
81
92
  description: ''
@@ -138,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements: []
140
151
  rubyforge_project:
141
- rubygems_version: 1.8.9
152
+ rubygems_version: 1.8.15
142
153
  signing_key:
143
154
  specification_version: 3
144
155
  summary: Cqrs tooling.