euston-eventstore 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/euston-eventstore.gemspec +9 -7
- data/lib/euston-eventstore.rb +2 -0
- data/lib/euston-eventstore/command_message.rb +26 -0
- data/lib/euston-eventstore/commit.rb +7 -2
- data/lib/euston-eventstore/optimistic_event_stream.rb +11 -5
- data/lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb +32 -0
- data/lib/euston-eventstore/persistence/mongodb/mongo_commit.rb +11 -3
- data/lib/euston-eventstore/persistence/mongodb/mongo_config.rb +2 -6
- data/lib/euston-eventstore/persistence/mongodb/mongo_event_message.rb +6 -5
- data/lib/euston-eventstore/persistence/mongodb/mongo_persistence_engine.rb +40 -27
- data/lib/euston-eventstore/persistence/mongodb/mongo_persistence_factory.rb +1 -1
- data/lib/euston-eventstore/persistence/mongodb/mongo_snapshot.rb +4 -4
- data/lib/euston-eventstore/persistence/mongodb/mongo_stream_head.rb +2 -2
- data/lib/euston-eventstore/repository.rb +2 -1
- data/lib/euston-eventstore/version.rb +1 -1
- data/spec/spec_helper.rb +2 -3
- metadata +32 -30
data/euston-eventstore.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'euston-eventstore'
|
3
|
-
s.version = '1.
|
4
|
-
s.date = '2011-10-
|
3
|
+
s.version = '1.2.0'
|
4
|
+
s.date = '2011-10-12'
|
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']
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
Rakefile
|
15
15
|
euston-eventstore.gemspec
|
16
16
|
lib/euston-eventstore.rb
|
17
|
+
lib/euston-eventstore/command_message.rb
|
17
18
|
lib/euston-eventstore/commit.rb
|
18
19
|
lib/euston-eventstore/constants.rb
|
19
20
|
lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
|
@@ -23,6 +24,7 @@ Gem::Specification.new do |s|
|
|
23
24
|
lib/euston-eventstore/event_message.rb
|
24
25
|
lib/euston-eventstore/optimistic_event_store.rb
|
25
26
|
lib/euston-eventstore/optimistic_event_stream.rb
|
27
|
+
lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb
|
26
28
|
lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
|
27
29
|
lib/euston-eventstore/persistence/mongodb/mongo_commit_id.rb
|
28
30
|
lib/euston-eventstore/persistence/mongodb/mongo_config.rb
|
@@ -51,17 +53,17 @@ Gem::Specification.new do |s|
|
|
51
53
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
52
54
|
|
53
55
|
s.add_dependency 'activesupport', '~> 3.0.9'
|
54
|
-
s.add_dependency 'euston', '~> 1.
|
56
|
+
s.add_dependency 'euston', '~> 1.2.0'
|
55
57
|
s.add_dependency 'hash-keys', '~> 1.0.0'
|
56
58
|
|
57
59
|
if RUBY_PLATFORM.to_s == 'java'
|
58
60
|
s.add_dependency 'json-jruby', '~> 1.5.0'
|
59
|
-
s.add_dependency 'jmongo', '~> 1.1.
|
61
|
+
s.add_dependency 'jmongo', '~> 1.1.1'
|
60
62
|
else
|
61
|
-
s.add_dependency 'bson', '~> 1.
|
62
|
-
s.add_dependency 'bson_ext', '~> 1.
|
63
|
+
s.add_dependency 'bson', '~> 1.4.0'
|
64
|
+
s.add_dependency 'bson_ext', '~> 1.4.0'
|
63
65
|
s.add_dependency 'json', '~> 1.5.0'
|
64
|
-
s.add_dependency 'mongo', '~> 1.
|
66
|
+
s.add_dependency 'mongo', '~> 1.4.0'
|
65
67
|
s.add_dependency 'uuid', '~> 2.3.0'
|
66
68
|
end
|
67
69
|
|
data/lib/euston-eventstore.rb
CHANGED
@@ -4,6 +4,7 @@ require 'hash-keys'
|
|
4
4
|
require 'euston-eventstore/commit'
|
5
5
|
require 'euston-eventstore/constants'
|
6
6
|
require 'euston-eventstore/errors'
|
7
|
+
require 'euston-eventstore/command_message'
|
7
8
|
require 'euston-eventstore/event_message'
|
8
9
|
require 'euston-eventstore/optimistic_event_store'
|
9
10
|
require 'euston-eventstore/optimistic_event_stream'
|
@@ -17,6 +18,7 @@ require 'euston-eventstore/persistence/stream_head'
|
|
17
18
|
require 'euston-eventstore/persistence/mongodb/mongo_commit'
|
18
19
|
require 'euston-eventstore/persistence/mongodb/mongo_commit_id'
|
19
20
|
require 'euston-eventstore/persistence/mongodb/mongo_config'
|
21
|
+
require 'euston-eventstore/persistence/mongodb/mongo_command_message'
|
20
22
|
require 'euston-eventstore/persistence/mongodb/mongo_event_message'
|
21
23
|
require 'euston-eventstore/persistence/mongodb/mongo_persistence_engine'
|
22
24
|
require 'euston-eventstore/persistence/mongodb/mongo_persistence_factory'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Euston
|
2
|
+
module EventStore
|
3
|
+
# Represents a single element in a stream of commands.
|
4
|
+
class CommandMessage
|
5
|
+
|
6
|
+
def initialize arg = nil
|
7
|
+
if arg.is_a?(Hash) && (arg.keys & ['body','headers']).size == 2
|
8
|
+
@body, @headers = arg.values_at('body','headers')
|
9
|
+
else
|
10
|
+
@headers = {}
|
11
|
+
@body = arg
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{ :headers => @headers, :body => @body }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Gets the metadata which provides additional, unstructured information about this command.
|
20
|
+
attr_reader :headers
|
21
|
+
|
22
|
+
# Gets or sets the actual comman body.
|
23
|
+
attr_reader :body
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -11,7 +11,8 @@ module Euston
|
|
11
11
|
:commit_sequence => 1,
|
12
12
|
:commit_timestamp => Time.now.utc,
|
13
13
|
:headers => OpenStruct.new,
|
14
|
-
:events => []
|
14
|
+
:events => [],
|
15
|
+
:commands => []
|
15
16
|
}
|
16
17
|
values = defaults.merge hash
|
17
18
|
defaults.keys.each { |key| instance_variable_set "@#{key}", values[key] }
|
@@ -25,7 +26,8 @@ module Euston
|
|
25
26
|
:commit_sequence => commit_sequence,
|
26
27
|
:commit_timestamp => commit_timestamp,
|
27
28
|
:headers => headers.is_a?(OpenStruct) ? headers.instance_variable_get(:@table) : headers,
|
28
|
-
:events => events
|
29
|
+
:events => events,
|
30
|
+
:commands => commands
|
29
31
|
}
|
30
32
|
end
|
31
33
|
# Gets the value which uniquely identifies the stream to which the commit belongs.
|
@@ -49,6 +51,9 @@ module Euston
|
|
49
51
|
# Gets the collection of event messages to be committed as a single unit.
|
50
52
|
attr_reader :events
|
51
53
|
|
54
|
+
# Gets the collection of command messages to be committed as a single unit.
|
55
|
+
attr_reader :commands
|
56
|
+
|
52
57
|
def ==(other)
|
53
58
|
(other.is_a? Commit) && (@stream_id == other.stream_id) && (@commit_id == other.commit_id)
|
54
59
|
end
|
@@ -5,6 +5,7 @@ module Euston
|
|
5
5
|
@persistence = options[:persistence]
|
6
6
|
@committed_events = []
|
7
7
|
@committed_headers = {}
|
8
|
+
@uncommitted_commands = []
|
8
9
|
@uncommitted_events = []
|
9
10
|
@uncommitted_headers = {}
|
10
11
|
@commit_sequence = 0
|
@@ -31,13 +32,17 @@ module Euston
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
attr_reader :stream_id, :stream_revision, :commit_sequence, :committed_events, :committed_headers, :uncommitted_events, :uncommitted_headers
|
35
|
+
attr_reader :stream_id, :stream_revision, :commit_sequence, :committed_events, :committed_headers, :uncommitted_commands, :uncommitted_events, :uncommitted_headers
|
35
36
|
|
36
|
-
def <<(
|
37
|
-
|
37
|
+
def <<(message)
|
38
|
+
return if message.nil? || message.body.nil?
|
39
|
+
|
40
|
+
@uncommitted_commands << message if message.is_a? CommandMessage
|
41
|
+
@uncommitted_events << message if message.is_a? EventMessage
|
38
42
|
end
|
39
43
|
|
40
44
|
def clear_changes
|
45
|
+
@uncommitted_commands = []
|
41
46
|
@uncommitted_events = []
|
42
47
|
@uncommitted_headers = {}
|
43
48
|
end
|
@@ -66,11 +71,12 @@ module Euston
|
|
66
71
|
:commit_sequence => commit_sequence + 1,
|
67
72
|
:commit_timestamp => Time.now.utc,
|
68
73
|
:headers => uncommitted_headers,
|
69
|
-
:events => uncommitted_events
|
74
|
+
:events => uncommitted_events,
|
75
|
+
:commands => uncommitted_commands
|
70
76
|
end
|
71
77
|
|
72
78
|
def has_changes
|
73
|
-
!uncommitted_events.empty?
|
79
|
+
!uncommitted_commands.empty? || !uncommitted_events.empty?
|
74
80
|
end
|
75
81
|
|
76
82
|
def persist_changes(commit_id)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Euston
|
2
|
+
module EventStore
|
3
|
+
module Persistence
|
4
|
+
module Mongodb
|
5
|
+
module MongoCommandMessage
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def from_hash hash
|
10
|
+
hash.recursive_symbolize_keys!
|
11
|
+
|
12
|
+
message = CommandMessage.new hash[:body]
|
13
|
+
message.instance_variable_set :@headers, hash[:headers]
|
14
|
+
message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
{
|
20
|
+
:headers => headers,
|
21
|
+
:body => body.to_hash.recursive_stringify_symbol_values!
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class CommandMessage
|
29
|
+
include Persistence::Mongodb::MongoCommandMessage
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -3,7 +3,7 @@ module Euston
|
|
3
3
|
module Persistence
|
4
4
|
module Mongodb
|
5
5
|
module MongoCommit
|
6
|
-
extend
|
6
|
+
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
9
|
alias_method :original_initialize, :initialize
|
@@ -18,8 +18,10 @@ module Euston
|
|
18
18
|
|
19
19
|
id = hash['_id']
|
20
20
|
events = hash['events'].sort_by { |e| e["stream_revision"] }.to_a
|
21
|
+
commands = hash['commands'] || []
|
21
22
|
stream_revision = events.last['stream_revision']
|
22
|
-
events = events.map { |e|
|
23
|
+
events = events.map { |e| MongoEventMessage.from_hash e['payload'] }
|
24
|
+
commands = commands.map { |c| MongoCommandMessage.from_hash c }
|
23
25
|
|
24
26
|
Euston::EventStore::Commit.new :stream_id => id['stream_id'],
|
25
27
|
:stream_revision => stream_revision,
|
@@ -27,7 +29,8 @@ module Euston
|
|
27
29
|
:commit_sequence => id['commit_sequence'],
|
28
30
|
:commit_timestamp => hash['commit_timestamp'],
|
29
31
|
:headers => hash['headers'].recursive_symbolize_keys!,
|
30
|
-
:events => events
|
32
|
+
:events => events,
|
33
|
+
:commands => commands
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -45,6 +48,7 @@ module Euston
|
|
45
48
|
hash.delete :commit_sequence
|
46
49
|
hash[:dispatched] ||= false
|
47
50
|
hash[:events] = hash[:events].map { |e| e.to_hash }
|
51
|
+
hash[:commands] = hash[:commands].map { |c| c.to_hash }
|
48
52
|
hash[:commit_timestamp] = hash[:commit_timestamp].to_f
|
49
53
|
hash
|
50
54
|
end
|
@@ -60,6 +64,10 @@ module Euston
|
|
60
64
|
event_hash
|
61
65
|
end
|
62
66
|
|
67
|
+
hash[:commands] = commands.map do |c|
|
68
|
+
c.to_hash
|
69
|
+
end
|
70
|
+
|
63
71
|
hash[:commit_timestamp_for_humans] = Time.at(hash[:commit_timestamp]).utc
|
64
72
|
|
65
73
|
hash
|
@@ -8,14 +8,10 @@ module Euston
|
|
8
8
|
include ::Singleton
|
9
9
|
|
10
10
|
def uri
|
11
|
-
@uri ||= 'mongodb://0.0.0.0:27017
|
11
|
+
@uri ||= 'mongodb://0.0.0.0:27017/?safe=true;fsync=true;w=1;'
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
@options ||= { :safe => true, :fsync => true, :journal => true }
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_writer :uri, :options
|
14
|
+
attr_writer :uri
|
19
15
|
attr_accessor :database, :logger
|
20
16
|
end
|
21
17
|
end
|
@@ -7,17 +7,18 @@ module Euston
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def from_hash(hash)
|
10
|
-
|
11
|
-
|
12
|
-
message.
|
10
|
+
hash.recursive_symbolize_keys!
|
11
|
+
|
12
|
+
message = EventMessage.new hash[:body]
|
13
|
+
message.instance_variable_set :@headers, hash[:headers]
|
13
14
|
message
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
def to_hash
|
18
19
|
{
|
19
|
-
:headers
|
20
|
-
:body
|
20
|
+
:headers => headers,
|
21
|
+
:body => body.to_hash.recursive_stringify_symbol_values!
|
21
22
|
}
|
22
23
|
end
|
23
24
|
end
|
@@ -22,23 +22,16 @@ module Euston
|
|
22
22
|
doc = { 'headers' => mongo_snapshot[:headers],
|
23
23
|
'payload' => mongo_snapshot[:payload] }.merge(id)
|
24
24
|
|
25
|
-
|
26
|
-
persisted_snapshots.update id, doc, :upsert => true, :safe => true
|
25
|
+
persisted_snapshots.update id, doc, :upsert => true
|
27
26
|
|
28
27
|
id = { '_id' => snapshot.stream_id }
|
29
28
|
|
30
|
-
|
31
|
-
if defined?(JMongo)
|
32
|
-
stream_head = MongoStreamHead.from_hash persisted_stream_heads.find(id).to_a.first
|
33
|
-
else
|
34
|
-
stream_head = MongoStreamHead.from_hash persisted_stream_heads.find_one(id)
|
35
|
-
end
|
29
|
+
stream_head = MongoStreamHead.from_hash persisted_stream_heads.find_one(id)
|
36
30
|
|
37
31
|
modifiers = { '$set' => { 'snapshot_revision' => snapshot.stream_revision,
|
38
32
|
'unsnapshotted' => stream_head.head_revision - snapshot.stream_revision } }
|
39
33
|
|
40
|
-
|
41
|
-
persisted_stream_heads.update id, modifiers, :safe => true
|
34
|
+
persisted_stream_heads.update id, modifiers
|
42
35
|
return true
|
43
36
|
rescue Mongo::OperationFailure
|
44
37
|
return false
|
@@ -50,19 +43,13 @@ module Euston
|
|
50
43
|
commit = attempt.to_mongo_commit
|
51
44
|
|
52
45
|
begin
|
53
|
-
|
54
|
-
persisted_commits.insert commit, :safe => true
|
46
|
+
persisted_commits.insert commit
|
55
47
|
|
56
48
|
update_stream_head_async attempt.stream_id, attempt.stream_revision, attempt.events.length
|
57
49
|
rescue Mongo::OperationFailure, NativeException => e
|
58
50
|
raise(Euston::EventStore::StorageError, e.message, e.backtrace) unless e.message.include? CONCURRENCY_EXCEPTION
|
59
51
|
|
60
|
-
|
61
|
-
if defined?(JMongo)
|
62
|
-
committed = persisted_commits.find(attempt.to_id_query).to_a.first
|
63
|
-
else
|
64
|
-
committed = persisted_commits.find_one(attempt.to_id_query)
|
65
|
-
end
|
52
|
+
committed = persisted_commits.find_one(attempt.to_id_query)
|
66
53
|
|
67
54
|
raise Euston::EventStore::DuplicateCommitError if !committed.nil? && committed['commit_id'] == attempt.commit_id
|
68
55
|
raise Euston::EventStore::ConcurrencyError
|
@@ -82,7 +69,7 @@ module Euston
|
|
82
69
|
order = [ 'events.stream_revision', Mongo::ASCENDING ]
|
83
70
|
end
|
84
71
|
|
85
|
-
persisted_commits.find(query
|
72
|
+
persisted_commits.find(query, :sort => order).to_a.map { |hash| MongoCommit.from_hash hash }
|
86
73
|
end
|
87
74
|
end
|
88
75
|
|
@@ -92,7 +79,7 @@ module Euston
|
|
92
79
|
'$lte' => { 'stream_id' => stream_id, 'stream_revision' => max_revision } } }
|
93
80
|
order = [ '_id', Mongo::DESCENDING ]
|
94
81
|
|
95
|
-
persisted_snapshots.find(query
|
82
|
+
persisted_snapshots.find(query, :sort => order, :limit => 1).map { |hash| MongoSnapshot::from_hash hash }.first
|
96
83
|
end
|
97
84
|
end
|
98
85
|
|
@@ -101,22 +88,25 @@ module Euston
|
|
101
88
|
query = { 'unsnapshotted' => { '$gte' => max_threshold } }
|
102
89
|
order = [ 'unsnapshotted', Mongo::DESCENDING ]
|
103
90
|
|
104
|
-
persisted_stream_heads.find(query
|
91
|
+
persisted_stream_heads.find(query, :sort => order).map { |hash| MongoStreamHead.from_hash hash }
|
105
92
|
end
|
106
93
|
end
|
107
94
|
|
108
|
-
def get_undispatched_commits
|
95
|
+
def get_undispatched_commits component_id = nil
|
109
96
|
try_mongo do
|
110
97
|
query = { 'dispatched' => false }
|
98
|
+
query['component_id'] = component_id unless component_id.nil?
|
99
|
+
|
111
100
|
order = [ 'commit_timestamp', Mongo::ASCENDING ]
|
112
101
|
|
113
|
-
persisted_commits.find(query
|
102
|
+
persisted_commits.find(query, :sort => order, :batch_size => 100).to_a.map { |hash| MongoCommit.from_hash hash }
|
114
103
|
end
|
115
104
|
end
|
116
105
|
|
117
106
|
def init
|
118
107
|
try_mongo do
|
119
108
|
persisted_commits.ensure_index [ ['dispatched', Mongo::ASCENDING],
|
109
|
+
['component_id', Mongo::ASCENDING],
|
120
110
|
['commit_timestamp', Mongo::ASCENDING] ], :unique => false, :name => 'dispatched_index'
|
121
111
|
|
122
112
|
persisted_commits.ensure_index [ ['_id.stream_id', Mongo::ASCENDING],
|
@@ -130,9 +120,33 @@ module Euston
|
|
130
120
|
end
|
131
121
|
|
132
122
|
def mark_commit_as_dispatched(commit)
|
123
|
+
mark_commits_as_dispatched [commit]
|
124
|
+
end
|
125
|
+
|
126
|
+
def mark_commits_as_dispatched(commits)
|
127
|
+
return if commits.empty?
|
128
|
+
|
129
|
+
try_mongo do
|
130
|
+
id_queries = commits.map { |c| c.to_id_query }
|
131
|
+
query = { '$or' => id_queries }
|
132
|
+
|
133
|
+
persisted_commits.update query, { '$set' => { 'dispatched' => true }, '$unset' => { 'component_id' => 1 } }, :multi => true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def take_ownership_of_undispatched_commits component_id
|
133
138
|
try_mongo do
|
134
|
-
|
135
|
-
|
139
|
+
new_commits_eligible_for_dispatch = { 'component_id' => nil,
|
140
|
+
'dispatched' => false }
|
141
|
+
|
142
|
+
commits_stuck_in_other_components = { 'component_id' => { '$ne' => nil } ,
|
143
|
+
'dispatched' => false,
|
144
|
+
'commit_timestamp' => Time.now.to_f - 60 }
|
145
|
+
|
146
|
+
query = { '$or' => [ new_commits_eligible_for_dispatch, commits_stuck_in_other_components ] }
|
147
|
+
doc = { '$set' => { 'component_id' => component_id } }
|
148
|
+
|
149
|
+
persisted_commits.update query, doc, :multi => true
|
136
150
|
end
|
137
151
|
end
|
138
152
|
|
@@ -162,12 +176,11 @@ module Euston
|
|
162
176
|
|
163
177
|
def update_stream_head_async(stream_id, stream_revision, events_count)
|
164
178
|
Thread.fork do
|
165
|
-
# jmongo doesn't currently honour the safe mode on the connection, so we have to specify safe here
|
166
179
|
id = { '_id' => stream_id }
|
167
180
|
doc = { '$set' => { 'head_revision' => stream_revision },
|
168
181
|
'$inc' => { 'snapshot_revision' => 0, 'unsnapshotted' => events_count } }
|
169
182
|
|
170
|
-
persisted_stream_heads.update id, doc, :upsert => true
|
183
|
+
persisted_stream_heads.update id, doc, :upsert => true
|
171
184
|
end
|
172
185
|
end
|
173
186
|
|
@@ -17,7 +17,7 @@ module Euston
|
|
17
17
|
class MongoPersistenceFactory
|
18
18
|
def self.build
|
19
19
|
config = Config.instance
|
20
|
-
options =
|
20
|
+
options = {}
|
21
21
|
options.merge!(:logger => config.logger) unless config.logger.nil?
|
22
22
|
|
23
23
|
@connection ||= Mongo::Connection.from_uri config.uri, options
|
@@ -11,10 +11,10 @@ module Euston
|
|
11
11
|
|
12
12
|
id = hash['_id']
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
Snapshot.new id['stream_id'],
|
15
|
+
id['stream_revision'],
|
16
|
+
hash['payload'].recursive__symbolize__keys!,
|
17
|
+
hash['headers'].recursive__symbolize__keys!
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -3,12 +3,12 @@ module Euston
|
|
3
3
|
module Persistence
|
4
4
|
module Mongodb
|
5
5
|
module MongoStreamHead
|
6
|
-
extend
|
6
|
+
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def from_hash hash
|
10
10
|
return nil if hash.nil?
|
11
|
-
|
11
|
+
StreamHead.new hash['_id'], hash['head_revision'], hash['snapshot_revision']
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -10,7 +10,8 @@ module Euston
|
|
10
10
|
|
11
11
|
def save aggregate
|
12
12
|
stream = event_store.open_stream :stream_id => aggregate.aggregate_id
|
13
|
-
aggregate.uncommitted_events.each { |e| stream <<
|
13
|
+
aggregate.uncommitted_events.each { |e| stream << EventStore::EventMessage.new(e.to_hash.stringify__keys) }
|
14
|
+
aggregate.uncommitted_commands.each { |c| stream << EventStore::CommandMessage.new(c.to_hash.stringify__keys) }
|
14
15
|
stream.uncommitted_headers[:aggregate_type] = aggregate.class.to_s
|
15
16
|
stream.commit_changes Euston.uuid.generate
|
16
17
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,14 +28,13 @@ require 'support/array_enumeration_counter'
|
|
28
28
|
|
29
29
|
mongo_config = Euston::EventStore::Persistence::Mongodb::Config.instance
|
30
30
|
mongo_config.database = 'event_store_tests'
|
31
|
-
mongo_config.options = { :safe => true, :fsync => true, :journal => true } #, :logger => Logger.new(STDOUT)
|
32
31
|
|
33
32
|
RSpec.configure do |config|
|
34
33
|
config.fail_fast = true
|
35
34
|
|
36
35
|
config.before :each do
|
37
|
-
connection = Mongo::Connection.from_uri
|
38
|
-
db = connection.db
|
36
|
+
connection = Mongo::Connection.from_uri mongo_config.uri
|
37
|
+
db = connection.db mongo_config.database
|
39
38
|
db.collections.select { |c| c.name !~ /system/ }.each { |c| db.drop_collection c.name }
|
40
39
|
end
|
41
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: euston-eventstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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: 2011-10-
|
13
|
+
date: 2011-10-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement: &
|
17
|
+
requirement: &81168440 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,21 +22,21 @@ dependencies:
|
|
22
22
|
version: 3.0.9
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *81168440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: euston
|
28
|
-
requirement: &
|
28
|
+
requirement: &80665360 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *80665360
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: hash-keys
|
39
|
-
requirement: &
|
39
|
+
requirement: &80664300 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,32 +44,32 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *80664300
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bson
|
50
|
-
requirement: &
|
50
|
+
requirement: &80662450 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 1.4.0
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *80662450
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: bson_ext
|
61
|
-
requirement: &
|
61
|
+
requirement: &80660670 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 1.
|
66
|
+
version: 1.4.0
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *80660670
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: json
|
72
|
-
requirement: &
|
72
|
+
requirement: &80659140 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,21 +77,21 @@ dependencies:
|
|
77
77
|
version: 1.5.0
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *80659140
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: mongo
|
83
|
-
requirement: &
|
83
|
+
requirement: &80656520 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
88
|
+
version: 1.4.0
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *80656520
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: uuid
|
94
|
-
requirement: &
|
94
|
+
requirement: &80655690 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ~>
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: 2.3.0
|
100
100
|
type: :runtime
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *80655690
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: awesome_print
|
105
|
-
requirement: &
|
105
|
+
requirement: &80654900 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ~>
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: 0.4.0
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *80654900
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: fuubar
|
116
|
-
requirement: &
|
116
|
+
requirement: &80651070 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ~>
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: 0.0.0
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *80651070
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rake
|
127
|
-
requirement: &
|
127
|
+
requirement: &80650260 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: 0.9.2
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *80650260
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: rspec
|
138
|
-
requirement: &
|
138
|
+
requirement: &80648850 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ~>
|
@@ -143,7 +143,7 @@ dependencies:
|
|
143
143
|
version: 2.6.0
|
144
144
|
type: :development
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *80648850
|
147
147
|
description: Ruby port for Jonathan Oliver's EventStore. See https://github.com/joliver/EventStore
|
148
148
|
for details.
|
149
149
|
email:
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- Rakefile
|
158
158
|
- euston-eventstore.gemspec
|
159
159
|
- lib/euston-eventstore.rb
|
160
|
+
- lib/euston-eventstore/command_message.rb
|
160
161
|
- lib/euston-eventstore/commit.rb
|
161
162
|
- lib/euston-eventstore/constants.rb
|
162
163
|
- lib/euston-eventstore/dispatcher/asynchronous_dispatcher.rb
|
@@ -166,6 +167,7 @@ files:
|
|
166
167
|
- lib/euston-eventstore/event_message.rb
|
167
168
|
- lib/euston-eventstore/optimistic_event_store.rb
|
168
169
|
- lib/euston-eventstore/optimistic_event_stream.rb
|
170
|
+
- lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb
|
169
171
|
- lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
|
170
172
|
- lib/euston-eventstore/persistence/mongodb/mongo_commit_id.rb
|
171
173
|
- lib/euston-eventstore/persistence/mongodb/mongo_config.rb
|