euston-eventstore 1.2.0-java → 1.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'euston-eventstore'
3
- s.version = '1.2.0'
4
- s.date = '2011-10-12'
3
+ s.version = '1.2.1'
4
+ s.date = '2011-10-13'
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']
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb
28
28
  lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
29
29
  lib/euston-eventstore/persistence/mongodb/mongo_commit_id.rb
30
+ lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb
30
31
  lib/euston-eventstore/persistence/mongodb/mongo_config.rb
31
32
  lib/euston-eventstore/persistence/mongodb/mongo_event_message.rb
32
33
  lib/euston-eventstore/persistence/mongodb/mongo_persistence_engine.rb
@@ -17,6 +17,7 @@ require 'euston-eventstore/dispatcher/synchronous_dispatcher'
17
17
  require 'euston-eventstore/persistence/stream_head'
18
18
  require 'euston-eventstore/persistence/mongodb/mongo_commit'
19
19
  require 'euston-eventstore/persistence/mongodb/mongo_commit_id'
20
+ require 'euston-eventstore/persistence/mongodb/mongo_concurrency_detection'
20
21
  require 'euston-eventstore/persistence/mongodb/mongo_config'
21
22
  require 'euston-eventstore/persistence/mongodb/mongo_command_message'
22
23
  require 'euston-eventstore/persistence/mongodb/mongo_event_message'
@@ -0,0 +1,31 @@
1
+ module Euston
2
+ module EventStore
3
+ module Persistence
4
+ module Mongodb
5
+ module MongoConcurrencyDetection
6
+ extend ActiveSupport::Concern
7
+
8
+ module InstanceMethods
9
+ def mongo_error_types_for_current_ruby_platform
10
+ errors = [ Mongo::OperationFailure ]
11
+ errors << NativeException if RUBY_PLATFORM.to_s == 'java'
12
+ errors
13
+ end
14
+
15
+ def detect_mongo_concurrency opts = {}, &block
16
+ begin
17
+ yield
18
+ rescue *mongo_error_types_for_current_ruby_platform => e
19
+ if e.message.include? "E11000"
20
+ opts.fetch(:on_e11000_error, ->(ex) { raise ConcurrencyError }).call e
21
+ else
22
+ opts.fetch(:on_other_error, ->(ex) { raise ex }).call e
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,6 +3,8 @@ module Euston
3
3
  module Persistence
4
4
  module Mongodb
5
5
  class MongoPersistenceEngine
6
+ include MongoConcurrencyDetection
7
+
6
8
  def initialize(store)
7
9
  @store = store
8
10
 
@@ -42,18 +44,18 @@ module Euston
42
44
  try_mongo do
43
45
  commit = attempt.to_mongo_commit
44
46
 
45
- begin
46
- persisted_commits.insert commit
47
-
48
- update_stream_head_async attempt.stream_id, attempt.stream_revision, attempt.events.length
49
- rescue Mongo::OperationFailure, NativeException => e
50
- raise(Euston::EventStore::StorageError, e.message, e.backtrace) unless e.message.include? CONCURRENCY_EXCEPTION
51
-
47
+ on_e11000_error = ->(e) do
52
48
  committed = persisted_commits.find_one(attempt.to_id_query)
53
-
54
49
  raise Euston::EventStore::DuplicateCommitError if !committed.nil? && committed['commit_id'] == attempt.commit_id
55
50
  raise Euston::EventStore::ConcurrencyError
56
51
  end
52
+
53
+ on_other_error = ->(e) { raise EventStore::StorageError, e.message, e.backtrace }
54
+
55
+ detect_mongo_concurrency :on_e11000_error => on_e11000_error, :on_other_error => on_other_error do
56
+ persisted_commits.insert commit
57
+ update_stream_head_async attempt.stream_id, attempt.stream_revision, attempt.events.length
58
+ end
57
59
  end
58
60
  end
59
61
 
@@ -1,5 +1,5 @@
1
1
  module Euston
2
2
  module EventStore
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: euston-eventstore
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.0
5
+ version: 1.2.1
6
6
  platform: java
7
7
  authors:
8
8
  - Lee Henson
@@ -10,106 +10,106 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-12 00:00:00.000000000 +01:00
13
+ date: 2011-10-13 00:00:00.000000000 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- version_requirements: &2210 !ruby/object:Gem::Requirement
18
+ version_requirements: &2218 !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
22
  version: 3.0.9
23
23
  none: false
24
- requirement: *2210
24
+ requirement: *2218
25
25
  prerelease: false
26
26
  type: :runtime
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: euston
29
- version_requirements: &2228 !ruby/object:Gem::Requirement
29
+ version_requirements: &2236 !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.0
34
34
  none: false
35
- requirement: *2228
35
+ requirement: *2236
36
36
  prerelease: false
37
37
  type: :runtime
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: hash-keys
40
- version_requirements: &2244 !ruby/object:Gem::Requirement
40
+ version_requirements: &2252 !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
44
  version: 1.0.0
45
45
  none: false
46
- requirement: *2244
46
+ requirement: *2252
47
47
  prerelease: false
48
48
  type: :runtime
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: json-jruby
51
- version_requirements: &2260 !ruby/object:Gem::Requirement
51
+ version_requirements: &2268 !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: 1.5.0
56
56
  none: false
57
- requirement: *2260
57
+ requirement: *2268
58
58
  prerelease: false
59
59
  type: :runtime
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: jmongo
62
- version_requirements: &2276 !ruby/object:Gem::Requirement
62
+ version_requirements: &2284 !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ~>
65
65
  - !ruby/object:Gem::Version
66
66
  version: 1.1.1
67
67
  none: false
68
- requirement: *2276
68
+ requirement: *2284
69
69
  prerelease: false
70
70
  type: :runtime
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: awesome_print
73
- version_requirements: &2292 !ruby/object:Gem::Requirement
73
+ version_requirements: &2300 !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.4.0
78
78
  none: false
79
- requirement: *2292
79
+ requirement: *2300
80
80
  prerelease: false
81
81
  type: :development
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: fuubar
84
- version_requirements: &2310 !ruby/object:Gem::Requirement
84
+ version_requirements: &2318 !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ~>
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.0.0
89
89
  none: false
90
- requirement: *2310
90
+ requirement: *2318
91
91
  prerelease: false
92
92
  type: :development
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rake
95
- version_requirements: &2326 !ruby/object:Gem::Requirement
95
+ version_requirements: &2334 !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - ~>
98
98
  - !ruby/object:Gem::Version
99
99
  version: 0.9.2
100
100
  none: false
101
- requirement: *2326
101
+ requirement: *2334
102
102
  prerelease: false
103
103
  type: :development
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rspec
106
- version_requirements: &2342 !ruby/object:Gem::Requirement
106
+ version_requirements: &2350 !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.6.0
111
111
  none: false
112
- requirement: *2342
112
+ requirement: *2350
113
113
  prerelease: false
114
114
  type: :development
115
115
  description: Ruby port for Jonathan Oliver's EventStore. See https://github.com/joliver/EventStore for details.
@@ -137,6 +137,7 @@ files:
137
137
  - lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb
138
138
  - lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
139
139
  - lib/euston-eventstore/persistence/mongodb/mongo_commit_id.rb
140
+ - lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb
140
141
  - lib/euston-eventstore/persistence/mongodb/mongo_config.rb
141
142
  - lib/euston-eventstore/persistence/mongodb/mongo_event_message.rb
142
143
  - lib/euston-eventstore/persistence/mongodb/mongo_persistence_engine.rb