ruby_event_store 0.36.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/Makefile +0 -9
- data/lib/ruby_event_store.rb +1 -0
- data/lib/ruby_event_store/client.rb +3 -21
- data/lib/ruby_event_store/errors.rb +1 -0
- data/lib/ruby_event_store/in_memory_repository.rb +3 -7
- data/lib/ruby_event_store/mappers/instrumented_mapper.rb +26 -0
- data/lib/ruby_event_store/projection.rb +5 -5
- data/lib/ruby_event_store/spec/event_lint.rb +73 -0
- data/lib/ruby_event_store/spec/event_repository_lint.rb +155 -201
- data/lib/ruby_event_store/specification.rb +43 -5
- data/lib/ruby_event_store/specification_result.rb +13 -39
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +7 -8
- data/exe/res-deprecated-read-api-migrator +0 -19
- data/lib/ruby_event_store/deprecated_read_api_rewriter.rb +0 -78
- data/lib/ruby_event_store/deprecated_read_api_runner.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c759197c7079350367b3669fefa272cf9eee74c46cb084e73be1412f0fcfd53
|
4
|
+
data.tar.gz: ba5fa3e80f410e2d773217eb02985fa34157bf12b9dec933e77cb1ea2d9eaff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10c08c3ec291f278d667f9768d20b912f69bdcc0e9c37162350e2017cb5462608ec95ae63a6bdbefccfd169916a2d930bc0ba000a0d2327c2b3804300d6f236
|
7
|
+
data.tar.gz: cd35806dfe6c323eec8c30c3e2ddef0146c694a620a4366f640aa0fa9a90f85f825f9cc8c9ed73f6e5bda6194339d254c197a1d1472be6442e018d8e82c55a36
|
data/Gemfile
CHANGED
@@ -4,8 +4,5 @@ gemspec
|
|
4
4
|
eval_gemfile File.expand_path('../lib/Gemfile.shared', __dir__)
|
5
5
|
|
6
6
|
gem 'protobuf_nested_struct'
|
7
|
-
gem 'parser'
|
8
|
-
gem 'unparser'
|
9
|
-
gem 'astrolabe'
|
10
7
|
gem 'google-protobuf', '= 3.6.1', source: 'https://gem.fury.io/pawelpacana/'
|
11
8
|
gem 'activesupport', '~> 5.0'
|
data/Makefile
CHANGED
@@ -2,17 +2,8 @@ GEM_VERSION = $(shell cat ../RES_VERSION)
|
|
2
2
|
GEM_NAME = ruby_event_store
|
3
3
|
REQUIRE = $(GEM_NAME)
|
4
4
|
IGNORE = RubyEventStore::InMemoryRepository\#append_with_synchronize \
|
5
|
-
RubyEventStore::InMemoryRepository\#normalize_to_array \
|
6
|
-
RubyEventStore::Client\#normalize_to_array \
|
7
|
-
RubyEventStore::Client::Within\#normalize_to_array \
|
8
5
|
RubyEventStore::Client::Within\#add_thread_subscribers \
|
9
6
|
RubyEventStore::Client::Within\#add_thread_global_subscribers \
|
10
|
-
RubyEventStore::DeprecatedReadAPIRunner* \
|
11
|
-
RubyEventStore::DeprecatedReadAPIRewriter* \
|
12
|
-
RubyEventStore::SpecificationResult\#count \
|
13
|
-
RubyEventStore::SpecificationResult\#direction \
|
14
|
-
RubyEventStore::SpecificationResult\#stream_name \
|
15
|
-
RubyEventStore::SpecificationResult\#global_stream? \
|
16
7
|
RubyEventStore::Client::Within\#call
|
17
8
|
SUBJECT ?= RubyEventStore*
|
18
9
|
|
data/lib/ruby_event_store.rb
CHANGED
@@ -18,6 +18,7 @@ require 'ruby_event_store/transform_keys'
|
|
18
18
|
require 'ruby_event_store/mappers/default'
|
19
19
|
require 'ruby_event_store/mappers/protobuf'
|
20
20
|
require 'ruby_event_store/mappers/null_mapper'
|
21
|
+
require 'ruby_event_store/mappers/instrumented_mapper'
|
21
22
|
require 'ruby_event_store/batch_enumerator'
|
22
23
|
require 'ruby_event_store/correlated_commands'
|
23
24
|
require 'ruby_event_store/link_by_metadata'
|
@@ -70,16 +70,6 @@ module RubyEventStore
|
|
70
70
|
self
|
71
71
|
end
|
72
72
|
|
73
|
-
# @deprecated Use {#read.event!(event_id)} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.33.0 More info}
|
74
|
-
def read_event(event_id)
|
75
|
-
warn <<~EOW
|
76
|
-
RubyEventStore::Client#read_event(event_id) has been deprecated.
|
77
|
-
Use `client.read.event!(event_id)` instead. Also available without
|
78
|
-
bang - return nil when no event is found.
|
79
|
-
EOW
|
80
|
-
read.event!(event_id)
|
81
|
-
end
|
82
|
-
|
83
73
|
# Starts building a query specification for reading events.
|
84
74
|
# {http://railseventstore.org/docs/read/ More info.}
|
85
75
|
#
|
@@ -170,7 +160,7 @@ module RubyEventStore
|
|
170
160
|
# @return [self]
|
171
161
|
def subscribe(handler=nil, to:, &handler2)
|
172
162
|
raise ArgumentError if handler && handler2
|
173
|
-
@subscribers[handler || handler2] +=
|
163
|
+
@subscribers[handler || handler2] += Array(to)
|
174
164
|
self
|
175
165
|
end
|
176
166
|
|
@@ -200,10 +190,6 @@ module RubyEventStore
|
|
200
190
|
@broker.add_thread_global_subscription(subscriber)
|
201
191
|
end
|
202
192
|
end
|
203
|
-
|
204
|
-
def normalize_to_array(objs)
|
205
|
-
return *objs
|
206
|
-
end
|
207
193
|
end
|
208
194
|
|
209
195
|
# Use for starting temporary subscriptions.
|
@@ -276,7 +262,7 @@ module RubyEventStore
|
|
276
262
|
# @param events [Array<Event, Proto>, Event, Proto] event(s) to serialize and overwrite again
|
277
263
|
# @return [self]
|
278
264
|
def overwrite(events_or_event)
|
279
|
-
events =
|
265
|
+
events = Array(events_or_event)
|
280
266
|
serialized_events = serialize_events(events)
|
281
267
|
repository.update_messages(serialized_events)
|
282
268
|
self
|
@@ -297,12 +283,8 @@ module RubyEventStore
|
|
297
283
|
end
|
298
284
|
end
|
299
285
|
|
300
|
-
def normalize_to_array(events)
|
301
|
-
return *events
|
302
|
-
end
|
303
|
-
|
304
286
|
def enrich_events_metadata(events)
|
305
|
-
events =
|
287
|
+
events = Array(events)
|
306
288
|
events.each{|event| enrich_event_metadata(event) }
|
307
289
|
events
|
308
290
|
end
|
@@ -4,6 +4,7 @@ module RubyEventStore
|
|
4
4
|
IncorrectStreamData = Class.new(StandardError)
|
5
5
|
SubscriberNotExist = Class.new(StandardError)
|
6
6
|
InvalidPageStart = Class.new(ArgumentError)
|
7
|
+
InvalidPageStop = Class.new(ArgumentError)
|
7
8
|
InvalidPageSize = Class.new(ArgumentError)
|
8
9
|
EventDuplicatedInStream = Class.new(StandardError)
|
9
10
|
ReservedInternalName = Class.new(StandardError)
|
@@ -15,7 +15,7 @@ module RubyEventStore
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def link_to_stream(event_ids, stream, expected_version)
|
18
|
-
events =
|
18
|
+
events = Array(event_ids).map {|eid| read_event(eid)}
|
19
19
|
add_to_stream(events, expected_version, stream, nil)
|
20
20
|
end
|
21
21
|
|
@@ -73,6 +73,7 @@ module RubyEventStore
|
|
73
73
|
events = events.select{|e| spec.with_types.any?{|x| x.eql?(e.event_type)}} if spec.with_types?
|
74
74
|
events = events.reverse if spec.backward?
|
75
75
|
events = events.drop(index_of(events, spec.start) + 1) unless spec.head?
|
76
|
+
events = events.take(index_of(events, spec.stop)) if spec.stop
|
76
77
|
events = events[0...spec.limit] if spec.limit?
|
77
78
|
events
|
78
79
|
end
|
@@ -85,13 +86,8 @@ module RubyEventStore
|
|
85
86
|
streams.fetch(name, Array.new)
|
86
87
|
end
|
87
88
|
|
88
|
-
def normalize_to_array(events)
|
89
|
-
return *events
|
90
|
-
end
|
91
|
-
|
92
89
|
def add_to_stream(events, expected_version, stream, include_global)
|
93
|
-
events
|
94
|
-
append_with_synchronize(events, expected_version, stream, include_global)
|
90
|
+
append_with_synchronize(Array(events), expected_version, stream, include_global)
|
95
91
|
end
|
96
92
|
|
97
93
|
def last_stream_version(stream)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RubyEventStore
|
2
|
+
module Mappers
|
3
|
+
class InstrumentedMapper
|
4
|
+
def initialize(mapper, instrumentation)
|
5
|
+
@mapper = mapper
|
6
|
+
@instrumentation = instrumentation
|
7
|
+
end
|
8
|
+
|
9
|
+
def event_to_serialized_record(domain_event)
|
10
|
+
instrumentation.instrument("serialize.mapper.rails_event_store", domain_event: domain_event) do
|
11
|
+
mapper.event_to_serialized_record(domain_event)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def serialized_record_to_event(record)
|
16
|
+
instrumentation.instrument("deserialize.mapper.rails_event_store", record: record) do
|
17
|
+
mapper.serialized_record_to_event(record)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :instrumentation, :mapper
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -27,7 +27,7 @@ module RubyEventStore
|
|
27
27
|
|
28
28
|
def when(events, handler)
|
29
29
|
Array(events).each do |event|
|
30
|
-
handlers[event] = handler
|
30
|
+
handlers[event.to_s] = handler
|
31
31
|
end
|
32
32
|
|
33
33
|
self
|
@@ -42,7 +42,7 @@ module RubyEventStore
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def call(event)
|
45
|
-
handlers.fetch(event.
|
45
|
+
handlers.fetch(event.type).(current_state, event)
|
46
46
|
end
|
47
47
|
|
48
48
|
def handled_events
|
@@ -71,13 +71,13 @@ module RubyEventStore
|
|
71
71
|
def reduce_from_streams(event_store, start, count)
|
72
72
|
raise ArgumentError.new('Start must be an array with event ids or :head') unless valid_starting_point?(start)
|
73
73
|
streams.zip(start_events(start)).reduce(initial_state) do |state, (stream_name, start_event_id)|
|
74
|
-
event_store.read.in_batches(count).stream(stream_name).from(start_event_id).
|
74
|
+
event_store.read.in_batches(count).stream(stream_name).from(start_event_id).reduce(state, &method(:transition))
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def reduce_from_all_streams(event_store, start, count)
|
79
79
|
raise ArgumentError.new('Start must be valid event id or :head') unless valid_starting_point?(start)
|
80
|
-
event_store.read.in_batches(count).from(start).
|
80
|
+
event_store.read.in_batches(count).from(start).reduce(initial_state, &method(:transition))
|
81
81
|
end
|
82
82
|
|
83
83
|
def start_events(start)
|
@@ -85,7 +85,7 @@ module RubyEventStore
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def transition(state, event)
|
88
|
-
handlers[event.
|
88
|
+
handlers[event.type].(state, event)
|
89
89
|
state
|
90
90
|
end
|
91
91
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
RSpec.shared_examples :event do |event_class|
|
2
|
+
it 'allows initialization' do
|
3
|
+
expect {
|
4
|
+
metadata = double(:metadata)
|
5
|
+
allow(metadata).to receive(:to_h).and_return({})
|
6
|
+
event_class.new(event_id: Object.new, data: Object.new, metadata: metadata)
|
7
|
+
}.not_to raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'provides event_id as string' do
|
11
|
+
event = event_class.new
|
12
|
+
expect(event.event_id).to be_an_instance_of(String)
|
13
|
+
expect(event.event_id).not_to eq ''
|
14
|
+
expect(event.event_id).not_to eq nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'provides message_id as string' do
|
18
|
+
event = event_class.new
|
19
|
+
expect(event.message_id).to be_an_instance_of(String)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'message_id is the same as event_id' do
|
23
|
+
event = event_class.new
|
24
|
+
expect(event.event_id).to eq event.message_id
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'exposes given event_id to string' do
|
28
|
+
event = event_class.new(event_id: 1234567890)
|
29
|
+
expect(event.event_id).to eq '1234567890'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'provides type as string' do
|
33
|
+
event = event_class.new
|
34
|
+
expect(event.type).to be_an_instance_of(String)
|
35
|
+
expect(event.type).not_to eq ''
|
36
|
+
expect(event.type).not_to eq nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "provides data" do
|
40
|
+
event = event_class.new
|
41
|
+
expect(event).to respond_to(:data).with(0).arguments
|
42
|
+
end
|
43
|
+
|
44
|
+
it "metadata allows to read keys" do
|
45
|
+
event = event_class.new
|
46
|
+
expect(event.metadata).to respond_to(:[]).with(1).arguments
|
47
|
+
end
|
48
|
+
|
49
|
+
it "metadata allows to set keys value" do
|
50
|
+
event = event_class.new
|
51
|
+
expect(event.metadata).to respond_to(:[]=).with(2).argument
|
52
|
+
end
|
53
|
+
|
54
|
+
it "metadata allows to fetch keys" do
|
55
|
+
event = event_class.new
|
56
|
+
expect(event.metadata).to respond_to(:fetch).with(1).argument
|
57
|
+
end
|
58
|
+
|
59
|
+
it "metadata allows to check existence of keys" do
|
60
|
+
event = event_class.new
|
61
|
+
expect(event.metadata).to respond_to(:has_key?).with(1).argument
|
62
|
+
end
|
63
|
+
|
64
|
+
it "metadata allows to iterate through keys" do
|
65
|
+
event = event_class.new
|
66
|
+
expect(event.metadata).to respond_to(:each_with_object).with(1).argument
|
67
|
+
end
|
68
|
+
|
69
|
+
it "metadata must convert to hash" do
|
70
|
+
event = event_class.new
|
71
|
+
expect(event.metadata).to respond_to(:to_h).with(0).argument
|
72
|
+
end
|
73
|
+
end
|
@@ -25,7 +25,7 @@ module RubyEventStore
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module RubyEventStore
|
28
|
-
RSpec.shared_examples :event_repository do |repository_class|
|
28
|
+
RSpec.shared_examples :event_repository do |repository_class, rescuable_concurrency_test_errors = []|
|
29
29
|
let(:repository) { subject || repository_class.new }
|
30
30
|
let(:mapper) { Mappers::NullMapper.new }
|
31
31
|
let(:specification) { Specification.new(SpecificationReader.new(repository, mapper)) }
|
@@ -42,65 +42,24 @@ module RubyEventStore
|
|
42
42
|
let(:version_2) { ExpectedVersion.new(2) }
|
43
43
|
let(:version_3) { ExpectedVersion.new(3) }
|
44
44
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
).to_a
|
51
|
-
end
|
52
|
-
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
).to_a
|
60
|
-
end
|
61
|
-
|
62
|
-
def read_events_forward(repository, stream, start, count)
|
63
|
-
repository.read(
|
64
|
-
specification
|
65
|
-
.stream(stream.name)
|
66
|
-
.from(start)
|
67
|
-
.limit(count)
|
68
|
-
.result
|
69
|
-
).to_a
|
70
|
-
end
|
71
|
-
|
72
|
-
def read_events_backward(repository, stream, start, count)
|
73
|
-
repository.read(
|
74
|
-
specification
|
75
|
-
.stream(stream.name)
|
76
|
-
.from(start)
|
77
|
-
.limit(count)
|
78
|
-
.backward
|
79
|
-
.result
|
80
|
-
).to_a
|
81
|
-
end
|
82
|
-
|
83
|
-
def read_all_streams_forward(repository, start, count)
|
84
|
-
repository.read(
|
85
|
-
specification
|
86
|
-
.from(start)
|
87
|
-
.limit(count)
|
88
|
-
.result
|
89
|
-
).to_a
|
90
|
-
end
|
91
|
-
|
92
|
-
def read_all_streams_backward(repository, start, count)
|
93
|
-
repository.read(
|
94
|
-
specification
|
95
|
-
.from(start)
|
96
|
-
.limit(count)
|
97
|
-
.backward
|
98
|
-
.result
|
99
|
-
).to_a
|
45
|
+
def read_events(scope, stream = nil, from: nil, to: nil, count: nil)
|
46
|
+
scope = scope.stream(stream.name) if stream
|
47
|
+
scope = scope.from(from) if from
|
48
|
+
scope = scope.to(to) if to
|
49
|
+
scope = scope.limit(count) if count
|
50
|
+
repository.read(scope.result).to_a
|
51
|
+
end
|
52
|
+
|
53
|
+
def read_events_forward(repository, stream = nil, from: nil, to: nil, count: nil)
|
54
|
+
read_events(specification, stream, from: from, to: to, count: count)
|
55
|
+
end
|
56
|
+
|
57
|
+
def read_events_backward(repository, stream = nil, from: nil, to: nil, count: nil)
|
58
|
+
read_events(specification.backward, stream, from: from, to: to, count: count)
|
100
59
|
end
|
101
60
|
|
102
61
|
it 'just created is empty' do
|
103
|
-
expect(
|
62
|
+
expect(read_events_forward(repository)).to be_empty
|
104
63
|
end
|
105
64
|
|
106
65
|
specify 'append_to_stream returns self' do
|
@@ -110,7 +69,6 @@ module RubyEventStore
|
|
110
69
|
end
|
111
70
|
|
112
71
|
specify 'link_to_stream returns self' do
|
113
|
-
skip unless test_link_events_to_stream
|
114
72
|
event0 = SRecord.new
|
115
73
|
event1 = SRecord.new
|
116
74
|
repository.
|
@@ -121,21 +79,20 @@ module RubyEventStore
|
|
121
79
|
|
122
80
|
specify 'adds an initial event to a new stream' do
|
123
81
|
repository.append_to_stream(event = SRecord.new, stream, version_none)
|
124
|
-
expect(
|
125
|
-
expect(
|
126
|
-
expect(
|
82
|
+
expect(read_events_forward(repository).first).to eq(event)
|
83
|
+
expect(read_events_forward(repository, stream).first).to eq(event)
|
84
|
+
expect(read_events_forward(repository, stream_other)).to be_empty
|
127
85
|
end
|
128
86
|
|
129
87
|
specify 'links an initial event to a new stream' do
|
130
|
-
skip unless test_link_events_to_stream
|
131
88
|
repository.
|
132
89
|
append_to_stream(event = SRecord.new, stream, version_none).
|
133
90
|
link_to_stream(event.event_id, stream_flow, version_none)
|
134
91
|
|
135
|
-
expect(
|
136
|
-
expect(
|
137
|
-
expect(
|
138
|
-
expect(
|
92
|
+
expect(read_events_forward(repository, count: 1).first).to eq(event)
|
93
|
+
expect(read_events_forward(repository, stream).first).to eq(event)
|
94
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event])
|
95
|
+
expect(read_events_forward(repository, stream_other)).to be_empty
|
139
96
|
end
|
140
97
|
|
141
98
|
specify 'adds multiple initial events to a new stream' do
|
@@ -143,12 +100,11 @@ module RubyEventStore
|
|
143
100
|
event0 = SRecord.new,
|
144
101
|
event1 = SRecord.new,
|
145
102
|
], stream, version_none)
|
146
|
-
expect(
|
147
|
-
expect(
|
103
|
+
expect(read_events_forward(repository, count: 2)).to eq([event0, event1])
|
104
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1])
|
148
105
|
end
|
149
106
|
|
150
107
|
specify 'links multiple initial events to a new stream' do
|
151
|
-
skip unless test_link_events_to_stream
|
152
108
|
repository.append_to_stream([
|
153
109
|
event0 = SRecord.new,
|
154
110
|
event1 = SRecord.new,
|
@@ -156,8 +112,8 @@ module RubyEventStore
|
|
156
112
|
event0.event_id,
|
157
113
|
event1.event_id,
|
158
114
|
], stream_flow, version_none)
|
159
|
-
expect(
|
160
|
-
expect(
|
115
|
+
expect(read_events_forward(repository, count: 2)).to eq([event0, event1])
|
116
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1])
|
161
117
|
end
|
162
118
|
|
163
119
|
specify 'correct expected version on second write' do
|
@@ -169,12 +125,11 @@ module RubyEventStore
|
|
169
125
|
event2 = SRecord.new,
|
170
126
|
event3 = SRecord.new,
|
171
127
|
], stream, version_1)
|
172
|
-
expect(
|
173
|
-
expect(
|
128
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1, event2, event3])
|
129
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
|
174
130
|
end
|
175
131
|
|
176
132
|
specify 'correct expected version on second link' do
|
177
|
-
skip unless test_link_events_to_stream
|
178
133
|
repository.append_to_stream([
|
179
134
|
event0 = SRecord.new,
|
180
135
|
event1 = SRecord.new,
|
@@ -185,8 +140,8 @@ module RubyEventStore
|
|
185
140
|
event0.event_id,
|
186
141
|
event1.event_id,
|
187
142
|
], stream_flow, version_1)
|
188
|
-
expect(
|
189
|
-
expect(
|
143
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1, event2, event3])
|
144
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event2, event3, event0, event1])
|
190
145
|
end
|
191
146
|
|
192
147
|
specify 'incorrect expected version on second write' do
|
@@ -201,12 +156,11 @@ module RubyEventStore
|
|
201
156
|
], stream, version_0)
|
202
157
|
end.to raise_error(WrongExpectedEventVersion)
|
203
158
|
|
204
|
-
expect(
|
205
|
-
expect(
|
159
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1])
|
160
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1])
|
206
161
|
end
|
207
162
|
|
208
163
|
specify 'incorrect expected version on second link' do
|
209
|
-
skip unless test_link_events_to_stream
|
210
164
|
repository.append_to_stream([
|
211
165
|
event0 = SRecord.new,
|
212
166
|
event1 = SRecord.new,
|
@@ -222,8 +176,8 @@ module RubyEventStore
|
|
222
176
|
], stream, version_0)
|
223
177
|
end.to raise_error(WrongExpectedEventVersion)
|
224
178
|
|
225
|
-
expect(
|
226
|
-
expect(
|
179
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1, event2, event3])
|
180
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1])
|
227
181
|
end
|
228
182
|
|
229
183
|
specify ':none on first and subsequent write' do
|
@@ -235,12 +189,11 @@ module RubyEventStore
|
|
235
189
|
eventB = SRecord.new,
|
236
190
|
], stream, version_none)
|
237
191
|
end.to raise_error(WrongExpectedEventVersion)
|
238
|
-
expect(
|
239
|
-
expect(
|
192
|
+
expect(read_events_forward(repository, count: 1)).to eq([eventA])
|
193
|
+
expect(read_events_forward(repository, stream)).to eq([eventA])
|
240
194
|
end
|
241
195
|
|
242
196
|
specify ':none on first and subsequent link' do
|
243
|
-
skip unless test_link_events_to_stream
|
244
197
|
repository.append_to_stream([
|
245
198
|
eventA = SRecord.new,
|
246
199
|
eventB = SRecord.new,
|
@@ -251,8 +204,8 @@ module RubyEventStore
|
|
251
204
|
repository.link_to_stream([eventB.event_id], stream_flow, version_none)
|
252
205
|
end.to raise_error(WrongExpectedEventVersion)
|
253
206
|
|
254
|
-
expect(
|
255
|
-
expect(
|
207
|
+
expect(read_events_forward(repository, count: 1)).to eq([eventA])
|
208
|
+
expect(read_events_forward(repository, stream_flow)).to eq([eventA])
|
256
209
|
end
|
257
210
|
|
258
211
|
specify ':any allows stream with best-effort order and no guarantee' do
|
@@ -264,12 +217,11 @@ module RubyEventStore
|
|
264
217
|
event2 = SRecord.new,
|
265
218
|
event3 = SRecord.new,
|
266
219
|
], stream, version_any)
|
267
|
-
expect(
|
268
|
-
expect(
|
220
|
+
expect(read_events_forward(repository, count: 4).to_set).to eq(Set.new([event0, event1, event2, event3]))
|
221
|
+
expect(read_events_forward(repository, stream).to_set).to eq(Set.new([event0, event1, event2, event3]))
|
269
222
|
end
|
270
223
|
|
271
224
|
specify ':any allows linking in stream with best-effort order and no guarantee' do
|
272
|
-
skip unless test_link_events_to_stream
|
273
225
|
repository.append_to_stream([
|
274
226
|
event0 = SRecord.new,
|
275
227
|
event1 = SRecord.new,
|
@@ -284,12 +236,11 @@ module RubyEventStore
|
|
284
236
|
event2.event_id, event3.event_id,
|
285
237
|
], stream_flow, version_any)
|
286
238
|
|
287
|
-
expect(
|
288
|
-
expect(
|
239
|
+
expect(read_events_forward(repository, count: 4).to_set).to eq(Set.new([event0, event1, event2, event3]))
|
240
|
+
expect(read_events_forward(repository, stream_flow).to_set).to eq(Set.new([event0, event1, event2, event3]))
|
289
241
|
end
|
290
242
|
|
291
243
|
specify ':auto queries for last position in given stream' do
|
292
|
-
skip unless test_expected_version_auto
|
293
244
|
repository.append_to_stream([
|
294
245
|
eventA = SRecord.new,
|
295
246
|
eventB = SRecord.new,
|
@@ -306,8 +257,6 @@ module RubyEventStore
|
|
306
257
|
end
|
307
258
|
|
308
259
|
specify ':auto queries for last position in given stream when linking' do
|
309
|
-
skip unless test_expected_version_auto
|
310
|
-
skip unless test_link_events_to_stream
|
311
260
|
repository.append_to_stream([
|
312
261
|
eventA = SRecord.new,
|
313
262
|
eventB = SRecord.new,
|
@@ -325,7 +274,6 @@ module RubyEventStore
|
|
325
274
|
end
|
326
275
|
|
327
276
|
specify ':auto starts from 0' do
|
328
|
-
skip unless test_expected_version_auto
|
329
277
|
repository.append_to_stream([
|
330
278
|
event0 = SRecord.new,
|
331
279
|
], stream, version_auto)
|
@@ -337,8 +285,6 @@ module RubyEventStore
|
|
337
285
|
end
|
338
286
|
|
339
287
|
specify ':auto linking starts from 0' do
|
340
|
-
skip unless test_expected_version_auto
|
341
|
-
skip unless test_link_events_to_stream
|
342
288
|
repository.append_to_stream([
|
343
289
|
event0 = SRecord.new,
|
344
290
|
], stream_other, version_auto)
|
@@ -353,7 +299,6 @@ module RubyEventStore
|
|
353
299
|
end
|
354
300
|
|
355
301
|
specify ':auto queries for last position and follows in incremental way' do
|
356
|
-
skip unless test_expected_version_auto
|
357
302
|
# It is expected that there is higher level lock
|
358
303
|
# So this query is safe from race conditions
|
359
304
|
repository.append_to_stream([
|
@@ -364,16 +309,14 @@ module RubyEventStore
|
|
364
309
|
event2 = SRecord.new,
|
365
310
|
event3 = SRecord.new,
|
366
311
|
], stream, version_auto)
|
367
|
-
expect(
|
312
|
+
expect(read_events_forward(repository, count: 4)).to eq([
|
368
313
|
event0, event1,
|
369
314
|
event2, event3
|
370
315
|
])
|
371
|
-
expect(
|
316
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
|
372
317
|
end
|
373
318
|
|
374
319
|
specify ':auto queries for last position and follows in incremental way when linking' do
|
375
|
-
skip unless test_expected_version_auto
|
376
|
-
skip unless test_link_events_to_stream
|
377
320
|
repository.append_to_stream([
|
378
321
|
event0 = SRecord.new,
|
379
322
|
event1 = SRecord.new,
|
@@ -386,15 +329,14 @@ module RubyEventStore
|
|
386
329
|
repository.link_to_stream([
|
387
330
|
event2.event_id, event3.event_id,
|
388
331
|
], stream_flow, version_auto)
|
389
|
-
expect(
|
332
|
+
expect(read_events_forward(repository, count: 4)).to eq([
|
390
333
|
event0, event1,
|
391
334
|
event2, event3
|
392
335
|
])
|
393
|
-
expect(
|
336
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1, event2, event3])
|
394
337
|
end
|
395
338
|
|
396
339
|
specify ':auto is compatible with manual expectation' do
|
397
|
-
skip unless test_expected_version_auto
|
398
340
|
repository.append_to_stream([
|
399
341
|
event0 = SRecord.new,
|
400
342
|
event1 = SRecord.new,
|
@@ -403,13 +345,11 @@ module RubyEventStore
|
|
403
345
|
event2 = SRecord.new,
|
404
346
|
event3 = SRecord.new,
|
405
347
|
], stream, version_1)
|
406
|
-
expect(
|
407
|
-
expect(
|
348
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1, event2, event3])
|
349
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
|
408
350
|
end
|
409
351
|
|
410
352
|
specify ':auto is compatible with manual expectation when linking' do
|
411
|
-
skip unless test_expected_version_auto
|
412
|
-
skip unless test_link_events_to_stream
|
413
353
|
repository.append_to_stream([
|
414
354
|
event0 = SRecord.new,
|
415
355
|
event1 = SRecord.new,
|
@@ -420,12 +360,11 @@ module RubyEventStore
|
|
420
360
|
repository.link_to_stream([
|
421
361
|
event1.event_id,
|
422
362
|
], stream_flow, version_0)
|
423
|
-
expect(
|
424
|
-
expect(
|
363
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1,])
|
364
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1,])
|
425
365
|
end
|
426
366
|
|
427
367
|
specify 'manual is compatible with auto expectation' do
|
428
|
-
skip unless test_expected_version_auto
|
429
368
|
repository.append_to_stream([
|
430
369
|
event0 = SRecord.new,
|
431
370
|
event1 = SRecord.new,
|
@@ -434,13 +373,11 @@ module RubyEventStore
|
|
434
373
|
event2 = SRecord.new,
|
435
374
|
event3 = SRecord.new,
|
436
375
|
], stream, version_auto)
|
437
|
-
expect(
|
438
|
-
expect(
|
376
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1, event2, event3])
|
377
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
|
439
378
|
end
|
440
379
|
|
441
380
|
specify 'manual is compatible with auto expectation when linking' do
|
442
|
-
skip unless test_expected_version_auto
|
443
|
-
skip unless test_link_events_to_stream
|
444
381
|
repository.append_to_stream([
|
445
382
|
event0 = SRecord.new,
|
446
383
|
event1 = SRecord.new,
|
@@ -451,8 +388,8 @@ module RubyEventStore
|
|
451
388
|
repository.link_to_stream([
|
452
389
|
event1.event_id,
|
453
390
|
], stream_flow, version_auto)
|
454
|
-
expect(
|
455
|
-
expect(
|
391
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1])
|
392
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1])
|
456
393
|
end
|
457
394
|
|
458
395
|
specify 'unlimited concurrency for :any - everything should succeed', timeout: 10, mutant: false do
|
@@ -460,9 +397,8 @@ module RubyEventStore
|
|
460
397
|
verify_conncurency_assumptions
|
461
398
|
begin
|
462
399
|
concurrency_level = 4
|
463
|
-
|
464
|
-
|
465
|
-
wait_for_it = true
|
400
|
+
fail_occurred = false
|
401
|
+
wait_for_it = true
|
466
402
|
|
467
403
|
threads = concurrency_level.times.map do |i|
|
468
404
|
Thread.new do
|
@@ -482,8 +418,8 @@ module RubyEventStore
|
|
482
418
|
wait_for_it = false
|
483
419
|
threads.each(&:join)
|
484
420
|
expect(fail_occurred).to eq(false)
|
485
|
-
expect(
|
486
|
-
events_in_stream =
|
421
|
+
expect(read_events_forward(repository, stream).size).to eq(400)
|
422
|
+
events_in_stream = read_events_forward(repository, stream)
|
487
423
|
expect(events_in_stream.size).to eq(400)
|
488
424
|
events0 = events_in_stream.select do |ev|
|
489
425
|
ev.event_id.start_with?("0-")
|
@@ -496,13 +432,11 @@ module RubyEventStore
|
|
496
432
|
|
497
433
|
specify 'unlimited concurrency for :any - everything should succeed when linking', timeout: 10, mutant: false do
|
498
434
|
skip unless test_race_conditions_any
|
499
|
-
skip unless test_link_events_to_stream
|
500
435
|
verify_conncurency_assumptions
|
501
436
|
begin
|
502
437
|
concurrency_level = 4
|
503
|
-
|
504
|
-
|
505
|
-
wait_for_it = true
|
438
|
+
fail_occurred = false
|
439
|
+
wait_for_it = true
|
506
440
|
|
507
441
|
concurrency_level.times.map do |i|
|
508
442
|
100.times do |j|
|
@@ -529,8 +463,8 @@ module RubyEventStore
|
|
529
463
|
wait_for_it = false
|
530
464
|
threads.each(&:join)
|
531
465
|
expect(fail_occurred).to eq(false)
|
532
|
-
expect(
|
533
|
-
events_in_stream =
|
466
|
+
expect(read_events_forward(repository, stream_flow).size).to eq(400)
|
467
|
+
events_in_stream = read_events_forward(repository, stream_flow)
|
534
468
|
expect(events_in_stream.size).to eq(400)
|
535
469
|
events0 = events_in_stream.select do |ev|
|
536
470
|
ev.event_id.start_with?("0-")
|
@@ -541,8 +475,7 @@ module RubyEventStore
|
|
541
475
|
end
|
542
476
|
end
|
543
477
|
|
544
|
-
specify 'limited concurrency for :auto - some operations will fail without outside lock, stream is ordered' do
|
545
|
-
skip unless test_expected_version_auto
|
478
|
+
specify 'limited concurrency for :auto - some operations will fail without outside lock, stream is ordered', mutant: false do
|
546
479
|
skip unless test_race_conditions_auto
|
547
480
|
verify_conncurency_assumptions
|
548
481
|
begin
|
@@ -561,7 +494,7 @@ module RubyEventStore
|
|
561
494
|
SRecord.new(event_id: eid),
|
562
495
|
], stream, version_auto)
|
563
496
|
sleep(rand(concurrency_level) / 1000.0)
|
564
|
-
rescue WrongExpectedEventVersion
|
497
|
+
rescue WrongExpectedEventVersion, *rescuable_concurrency_test_errors
|
565
498
|
fail_occurred +=1
|
566
499
|
end
|
567
500
|
end
|
@@ -570,7 +503,7 @@ module RubyEventStore
|
|
570
503
|
wait_for_it = false
|
571
504
|
threads.each(&:join)
|
572
505
|
expect(fail_occurred).to be > 0
|
573
|
-
events_in_stream =
|
506
|
+
events_in_stream = read_events_forward(repository, stream)
|
574
507
|
expect(events_in_stream.size).to be < 400
|
575
508
|
expect(events_in_stream.size).to be >= 100
|
576
509
|
events0 = events_in_stream.select do |ev|
|
@@ -583,11 +516,8 @@ module RubyEventStore
|
|
583
516
|
end
|
584
517
|
end
|
585
518
|
|
586
|
-
specify 'limited concurrency for :auto - some operations will fail without outside lock, stream is ordered' do
|
587
|
-
skip unless test_expected_version_auto
|
519
|
+
specify 'limited concurrency for :auto - some operations will fail without outside lock, stream is ordered', mutant: false do
|
588
520
|
skip unless test_race_conditions_auto
|
589
|
-
skip unless test_link_events_to_stream
|
590
|
-
|
591
521
|
verify_conncurency_assumptions
|
592
522
|
begin
|
593
523
|
concurrency_level = 4
|
@@ -612,7 +542,7 @@ module RubyEventStore
|
|
612
542
|
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
613
543
|
repository.link_to_stream(eid, stream, version_auto)
|
614
544
|
sleep(rand(concurrency_level) / 1000.0)
|
615
|
-
rescue WrongExpectedEventVersion
|
545
|
+
rescue WrongExpectedEventVersion, *rescuable_concurrency_test_errors
|
616
546
|
fail_occurred +=1
|
617
547
|
end
|
618
548
|
end
|
@@ -621,7 +551,7 @@ module RubyEventStore
|
|
621
551
|
wait_for_it = false
|
622
552
|
threads.each(&:join)
|
623
553
|
expect(fail_occurred).to be > 0
|
624
|
-
events_in_stream =
|
554
|
+
events_in_stream = read_events_forward(repository, stream)
|
625
555
|
expect(events_in_stream.size).to be < 400
|
626
556
|
expect(events_in_stream.size).to be >= 100
|
627
557
|
events0 = events_in_stream.select do |ev|
|
@@ -637,27 +567,26 @@ module RubyEventStore
|
|
637
567
|
it 'appended event is stored in given stream' do
|
638
568
|
expected_event = SRecord.new
|
639
569
|
repository.append_to_stream(expected_event, stream, version_any)
|
640
|
-
expect(
|
641
|
-
expect(
|
642
|
-
expect(
|
570
|
+
expect(read_events_forward(repository, count: 1).first).to eq(expected_event)
|
571
|
+
expect(read_events_forward(repository, stream).first).to eq(expected_event)
|
572
|
+
expect(read_events_forward(repository, stream_other)).to be_empty
|
643
573
|
end
|
644
574
|
|
645
575
|
it 'data attributes are retrieved' do
|
646
576
|
event = SRecord.new(data: '{"order_id":3}')
|
647
577
|
repository.append_to_stream(event, stream, version_any)
|
648
|
-
retrieved_event =
|
578
|
+
retrieved_event = read_events_forward(repository, count: 1).first
|
649
579
|
expect(retrieved_event.data).to eq('{"order_id":3}')
|
650
580
|
end
|
651
581
|
|
652
582
|
it 'metadata attributes are retrieved' do
|
653
583
|
event = SRecord.new(metadata: '{"request_id":3}')
|
654
584
|
repository.append_to_stream(event, stream, version_any)
|
655
|
-
retrieved_event =
|
585
|
+
retrieved_event = read_events_forward(repository, count: 1).first
|
656
586
|
expect(retrieved_event.metadata).to eq('{"request_id":3}')
|
657
587
|
end
|
658
588
|
|
659
589
|
it 'data and metadata attributes are retrieved when linking' do
|
660
|
-
skip unless test_link_events_to_stream
|
661
590
|
event = SRecord.new(
|
662
591
|
data: '{"order_id":3}',
|
663
592
|
metadata: '{"request_id":4}',
|
@@ -665,7 +594,7 @@ module RubyEventStore
|
|
665
594
|
repository.
|
666
595
|
append_to_stream(event, stream, version_any).
|
667
596
|
link_to_stream(event.event_id, stream_flow, version_any)
|
668
|
-
retrieved_event =
|
597
|
+
retrieved_event = read_events_forward(repository, stream_flow).first
|
669
598
|
expect(retrieved_event.metadata).to eq('{"request_id":4}')
|
670
599
|
expect(retrieved_event.data).to eq('{"order_id":3}')
|
671
600
|
expect(event).to eq(retrieved_event)
|
@@ -676,20 +605,19 @@ module RubyEventStore
|
|
676
605
|
repository.append_to_stream(e2 = SRecord.new, stream_other, version_none)
|
677
606
|
|
678
607
|
repository.delete_stream(stream)
|
679
|
-
expect(
|
680
|
-
expect(
|
681
|
-
expect(
|
608
|
+
expect(read_events_forward(repository, stream)).to be_empty
|
609
|
+
expect(read_events_forward(repository, stream_other)).to eq([e2])
|
610
|
+
expect(read_events_forward(repository, count: 10)).to eq([e1,e2])
|
682
611
|
end
|
683
612
|
|
684
613
|
it 'does not have deleted streams with linked events' do
|
685
|
-
skip unless test_link_events_to_stream
|
686
614
|
repository.
|
687
615
|
append_to_stream(e1 = SRecord.new, stream, version_none).
|
688
616
|
link_to_stream(e1.event_id, stream_flow, version_none)
|
689
617
|
|
690
618
|
repository.delete_stream(stream_flow)
|
691
|
-
expect(
|
692
|
-
expect(
|
619
|
+
expect(read_events_forward(repository, stream_flow)).to be_empty
|
620
|
+
expect(read_events_forward(repository, count: 10)).to eq([e1])
|
693
621
|
end
|
694
622
|
|
695
623
|
it 'has or has not domain event' do
|
@@ -714,7 +642,6 @@ module RubyEventStore
|
|
714
642
|
end
|
715
643
|
|
716
644
|
it 'knows last event in stream when linked' do
|
717
|
-
skip unless test_link_events_to_stream
|
718
645
|
repository.append_to_stream([
|
719
646
|
e0 = SRecord.new(event_id: '00000000-0000-0000-0000-000000000001'),
|
720
647
|
e1 = SRecord.new(event_id: '00000000-0000-0000-0000-000000000002'),
|
@@ -744,20 +671,23 @@ module RubyEventStore
|
|
744
671
|
end
|
745
672
|
repository.append_to_stream(SRecord.new, stream_other, version_0)
|
746
673
|
|
747
|
-
expect(read_events_forward(repository, stream, :
|
748
|
-
expect(read_events_forward(repository, stream, :
|
749
|
-
expect(repository
|
750
|
-
expect(read_events_forward(repository, stream, events[4].event_id, 4)).to eq(events[5..8])
|
751
|
-
expect(read_events_forward(repository, stream, events[4].event_id, 100)).to eq(events[5..9])
|
674
|
+
expect(read_events_forward(repository, stream, count: 3)).to eq(events.first(3))
|
675
|
+
expect(read_events_forward(repository, stream, count: 100)).to eq(events)
|
676
|
+
expect(read_events_forward(repository, stream, from: events[4].event_id)).to eq(events[5..9])
|
677
|
+
expect(read_events_forward(repository, stream, from: events[4].event_id, count: 4)).to eq(events[5..8])
|
678
|
+
expect(read_events_forward(repository, stream, from: events[4].event_id, count: 100)).to eq(events[5..9])
|
679
|
+
expect(read_events_forward(repository, stream, to: events[4].event_id, count: 3)).to eq(events[0..2])
|
680
|
+
expect(read_events_forward(repository, stream, to: events[4].event_id, count: 100)).to eq(events[0..3])
|
752
681
|
|
753
|
-
expect(read_events_backward(repository, stream, :
|
754
|
-
expect(read_events_backward(repository, stream, :
|
755
|
-
expect(read_events_backward(repository, stream, events[4].event_id, 4)).to eq(events.first(4).reverse)
|
756
|
-
expect(read_events_backward(repository, stream, events[4].event_id, 100)).to eq(events.first(4).reverse)
|
682
|
+
expect(read_events_backward(repository, stream, count: 3)).to eq(events.last(3).reverse)
|
683
|
+
expect(read_events_backward(repository, stream, count: 100)).to eq(events.reverse)
|
684
|
+
expect(read_events_backward(repository, stream, from: events[4].event_id, count: 4)).to eq(events.first(4).reverse)
|
685
|
+
expect(read_events_backward(repository, stream, from: events[4].event_id, count: 100)).to eq(events.first(4).reverse)
|
686
|
+
expect(read_events_backward(repository, stream, to: events[4].event_id, count: 4)).to eq(events.last(4).reverse)
|
687
|
+
expect(read_events_backward(repository, stream, to: events[4].event_id, count: 100)).to eq(events.last(5).reverse)
|
757
688
|
end
|
758
689
|
|
759
690
|
it 'reads batch of linked events from stream forward & backward' do
|
760
|
-
skip unless test_link_events_to_stream
|
761
691
|
events = %w[
|
762
692
|
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
763
693
|
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
@@ -778,15 +708,19 @@ module RubyEventStore
|
|
778
708
|
end
|
779
709
|
repository.append_to_stream(SRecord.new, stream_other, version_0)
|
780
710
|
|
781
|
-
expect(read_events_forward(repository, stream_flow, :
|
782
|
-
expect(read_events_forward(repository, stream_flow, :
|
783
|
-
expect(read_events_forward(repository, stream_flow, events[4].event_id, 4)).to eq(events[5..8])
|
784
|
-
expect(read_events_forward(repository, stream_flow, events[4].event_id, 100)).to eq(events[5..9])
|
711
|
+
expect(read_events_forward(repository, stream_flow, count: 3)).to eq(events.first(3))
|
712
|
+
expect(read_events_forward(repository, stream_flow, count: 100)).to eq(events)
|
713
|
+
expect(read_events_forward(repository, stream_flow, from: events[4].event_id, count: 4)).to eq(events[5..8])
|
714
|
+
expect(read_events_forward(repository, stream_flow, from: events[4].event_id, count: 100)).to eq(events[5..9])
|
715
|
+
expect(read_events_forward(repository, stream_flow, to: events[4].event_id, count: 3)).to eq(events[0..2])
|
716
|
+
expect(read_events_forward(repository, stream_flow, to: events[4].event_id, count: 100)).to eq(events[0..3])
|
785
717
|
|
786
|
-
expect(read_events_backward(repository, stream_flow, :
|
787
|
-
expect(read_events_backward(repository, stream_flow, :
|
788
|
-
expect(read_events_backward(repository, stream_flow, events[4].event_id, 4)).to eq(events.first(4).reverse)
|
789
|
-
expect(read_events_backward(repository, stream_flow, events[4].event_id, 100)).to eq(events.first(4).reverse)
|
718
|
+
expect(read_events_backward(repository, stream_flow, count: 3)).to eq(events.last(3).reverse)
|
719
|
+
expect(read_events_backward(repository, stream_flow, count: 100)).to eq(events.reverse)
|
720
|
+
expect(read_events_backward(repository, stream_flow, from: events[4].event_id, count: 4)).to eq(events.first(4).reverse)
|
721
|
+
expect(read_events_backward(repository, stream_flow, from: events[4].event_id, count: 100)).to eq(events.first(4).reverse)
|
722
|
+
expect(read_events_backward(repository, stream_flow, to: events[4].event_id, count: 4)).to eq(events[6..9].reverse)
|
723
|
+
expect(read_events_backward(repository, stream_flow, to: events[4].event_id, count: 100)).to eq(events[5..9].reverse)
|
790
724
|
end
|
791
725
|
|
792
726
|
it 'reads all stream events forward & backward' do
|
@@ -799,12 +733,11 @@ module RubyEventStore
|
|
799
733
|
append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s2, version_0).
|
800
734
|
append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s2, version_1)
|
801
735
|
|
802
|
-
expect(
|
803
|
-
expect(
|
736
|
+
expect(read_events_forward(repository, s1)).to eq [a,c]
|
737
|
+
expect(read_events_backward(repository, s1)).to eq [c,a]
|
804
738
|
end
|
805
739
|
|
806
740
|
it 'reads all stream linked events forward & backward' do
|
807
|
-
skip unless test_link_events_to_stream
|
808
741
|
s1, fs1, fs2 = stream, stream_flow, stream_other
|
809
742
|
repository.
|
810
743
|
append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, version_none).
|
@@ -818,8 +751,8 @@ module RubyEventStore
|
|
818
751
|
link_to_stream('30963ed9-6349-450b-ac9b-8ea50115b3bd', fs2, version_0).
|
819
752
|
link_to_stream('5bdc58b7-e8a7-4621-afd6-ccb828d72457', fs2, version_1)
|
820
753
|
|
821
|
-
expect(
|
822
|
-
expect(
|
754
|
+
expect(read_events_forward(repository, fs1)).to eq [a,c]
|
755
|
+
expect(read_events_backward(repository, fs1)).to eq [c,a]
|
823
756
|
end
|
824
757
|
|
825
758
|
it 'reads batch of events from all streams forward & backward' do
|
@@ -839,19 +772,22 @@ module RubyEventStore
|
|
839
772
|
repository.append_to_stream(ev, Stream.new(SecureRandom.uuid), version_none)
|
840
773
|
end
|
841
774
|
|
842
|
-
expect(
|
843
|
-
expect(
|
844
|
-
expect(
|
845
|
-
expect(
|
775
|
+
expect(read_events_forward(repository, count: 3)).to eq(events.first(3))
|
776
|
+
expect(read_events_forward(repository, count: 100)).to eq(events)
|
777
|
+
expect(read_events_forward(repository, from: events[4].event_id, count: 4)).to eq(events[5..8])
|
778
|
+
expect(read_events_forward(repository, from: events[4].event_id, count: 100)).to eq(events[5..9])
|
779
|
+
expect(read_events_forward(repository, to: events[4].event_id, count: 3)).to eq(events[0..2])
|
780
|
+
expect(read_events_forward(repository, to: events[4].event_id, count: 100)).to eq(events[0..3])
|
846
781
|
|
847
|
-
expect(
|
848
|
-
expect(
|
849
|
-
expect(
|
850
|
-
expect(
|
782
|
+
expect(read_events_backward(repository, count: 3)).to eq(events.last(3).reverse)
|
783
|
+
expect(read_events_backward(repository, count: 100)).to eq(events.reverse)
|
784
|
+
expect(read_events_backward(repository, from: events[4].event_id, count: 4)).to eq(events.first(4).reverse)
|
785
|
+
expect(read_events_backward(repository, from: events[4].event_id, count: 100)).to eq(events.first(4).reverse)
|
786
|
+
expect(read_events_backward(repository, to: events[4].event_id, count: 4)).to eq(events.last(4).reverse)
|
787
|
+
expect(read_events_backward(repository, to: events[4].event_id, count: 100)).to eq(events.last(5).reverse)
|
851
788
|
end
|
852
789
|
|
853
790
|
it 'linked events do not affect reading from all streams - no duplicates' do
|
854
|
-
skip unless test_link_events_to_stream
|
855
791
|
events = %w[
|
856
792
|
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
857
793
|
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
@@ -870,15 +806,19 @@ module RubyEventStore
|
|
870
806
|
link_to_stream(ev.event_id, Stream.new(SecureRandom.uuid), version_none)
|
871
807
|
end
|
872
808
|
|
873
|
-
expect(
|
874
|
-
expect(
|
875
|
-
expect(
|
876
|
-
expect(
|
809
|
+
expect(read_events_forward(repository, count: 3)).to eq(events.first(3))
|
810
|
+
expect(read_events_forward(repository, count: 100)).to eq(events)
|
811
|
+
expect(read_events_forward(repository, from: events[4].event_id, count: 4)).to eq(events[5..8])
|
812
|
+
expect(read_events_forward(repository, from: events[4].event_id, count: 100)).to eq(events[5..9])
|
813
|
+
expect(read_events_forward(repository, to: events[4].event_id, count: 3)).to eq(events[0..2])
|
814
|
+
expect(read_events_forward(repository, to: events[4].event_id, count: 100)).to eq(events[0..3])
|
877
815
|
|
878
|
-
expect(
|
879
|
-
expect(
|
880
|
-
expect(
|
881
|
-
expect(
|
816
|
+
expect(read_events_backward(repository, count: 3)).to eq(events.last(3).reverse)
|
817
|
+
expect(read_events_backward(repository, count: 100)).to eq(events.reverse)
|
818
|
+
expect(read_events_backward(repository, from: events[4].event_id, count: 4)).to eq(events.first(4).reverse)
|
819
|
+
expect(read_events_backward(repository, from: events[4].event_id, count: 100)).to eq(events.first(4).reverse)
|
820
|
+
expect(read_events_backward(repository, to: events[4].event_id, count: 4)).to eq(events.last(4).reverse)
|
821
|
+
expect(read_events_backward(repository, to: events[4].event_id, count: 100)).to eq(events.last(5).reverse)
|
882
822
|
end
|
883
823
|
|
884
824
|
it 'reads events different uuid object but same content' do
|
@@ -889,11 +829,15 @@ module RubyEventStore
|
|
889
829
|
repository.append_to_stream(events.first, stream, version_none)
|
890
830
|
repository.append_to_stream(events.last, stream, version_0)
|
891
831
|
|
892
|
-
expect(
|
893
|
-
expect(
|
832
|
+
expect(read_events_forward(repository, from: "96c920b1-cdd0-40f4-907c-861b9fff7d02")).to eq([events.last])
|
833
|
+
expect(read_events_backward(repository, from: "56404f79-0ba0-4aa0-8524-dc3436368ca0")).to eq([events.first])
|
834
|
+
expect(read_events_forward(repository, to: "56404f79-0ba0-4aa0-8524-dc3436368ca0", count: 1)).to eq([events.first])
|
835
|
+
expect(read_events_backward(repository, to: "96c920b1-cdd0-40f4-907c-861b9fff7d02", count: 1)).to eq([events.last])
|
894
836
|
|
895
|
-
expect(read_events_forward(repository, stream, "96c920b1-cdd0-40f4-907c-861b9fff7d02"
|
896
|
-
expect(read_events_backward(repository, stream, "56404f79-0ba0-4aa0-8524-dc3436368ca0"
|
837
|
+
expect(read_events_forward(repository, stream, from: "96c920b1-cdd0-40f4-907c-861b9fff7d02")).to eq([events.last])
|
838
|
+
expect(read_events_backward(repository, stream, from: "56404f79-0ba0-4aa0-8524-dc3436368ca0")).to eq([events.first])
|
839
|
+
expect(read_events_forward(repository, stream, to: "56404f79-0ba0-4aa0-8524-dc3436368ca0", count: 1)).to eq([events.first])
|
840
|
+
expect(read_events_backward(repository, stream, to: "96c920b1-cdd0-40f4-907c-861b9fff7d02", count: 1)).to eq([events.last])
|
897
841
|
end
|
898
842
|
|
899
843
|
it 'does not allow same event twice in a stream' do
|
@@ -927,7 +871,6 @@ module RubyEventStore
|
|
927
871
|
end
|
928
872
|
|
929
873
|
it 'does not allow linking same event twice in a stream' do
|
930
|
-
skip unless test_link_events_to_stream
|
931
874
|
repository.append_to_stream([
|
932
875
|
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
933
876
|
], stream,
|
@@ -942,7 +885,7 @@ module RubyEventStore
|
|
942
885
|
event = SRecord.new(event_id: "df8b2ba3-4e2c-4888-8d14-4364855fa80e")
|
943
886
|
repository.append_to_stream(event, global_stream, version_any)
|
944
887
|
|
945
|
-
expect(
|
888
|
+
expect(read_events_forward(repository, count: 10)).to eq([event])
|
946
889
|
end
|
947
890
|
|
948
891
|
specify "events not persisted if append failed" do
|
@@ -961,7 +904,6 @@ module RubyEventStore
|
|
961
904
|
end
|
962
905
|
|
963
906
|
specify 'linking non-existent event' do
|
964
|
-
skip unless test_link_events_to_stream
|
965
907
|
expect do
|
966
908
|
repository.link_to_stream('72922e65-1b32-4e97-8023-03ae81dd3a27', stream_flow, version_none)
|
967
909
|
end.to raise_error do |err|
|
@@ -1133,6 +1075,18 @@ module RubyEventStore
|
|
1133
1075
|
|
1134
1076
|
expect(repository.read(specification.from(events[0].event_id).backward.read_first.result)).to be_nil
|
1135
1077
|
expect(repository.read(specification.from(events[0].event_id).backward.read_last.result)).to be_nil
|
1078
|
+
|
1079
|
+
expect(repository.read(specification.to(events[3].event_id).read_first.result)).to eq(events[0])
|
1080
|
+
expect(repository.read(specification.to(events[3].event_id).read_last.result)).to eq(events[2])
|
1081
|
+
|
1082
|
+
expect(repository.read(specification.to(events[2].event_id).backward.read_first.result)).to eq(events[4])
|
1083
|
+
expect(repository.read(specification.to(events[2].event_id).backward.read_last.result)).to eq(events[3])
|
1084
|
+
|
1085
|
+
expect(repository.read(specification.to(events[0].event_id).read_first.result)).to be_nil
|
1086
|
+
expect(repository.read(specification.to(events[0].event_id).read_last.result)).to be_nil
|
1087
|
+
|
1088
|
+
expect(repository.read(specification.to(events[4].event_id).backward.read_first.result)).to be_nil
|
1089
|
+
expect(repository.read(specification.to(events[4].event_id).backward.read_last.result)).to be_nil
|
1136
1090
|
end
|
1137
1091
|
|
1138
1092
|
context "#update_messages" do
|
@@ -1173,7 +1127,6 @@ module RubyEventStore
|
|
1173
1127
|
end
|
1174
1128
|
|
1175
1129
|
specify do
|
1176
|
-
skip unless test_link_events_to_stream
|
1177
1130
|
event_1 = SRecord.new(event_id: '8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea')
|
1178
1131
|
event_2 = SRecord.new(event_id: '8cee1139-4f96-483a-a175-2b947283c3c7')
|
1179
1132
|
event_3 = SRecord.new(event_id: 'd345f86d-b903-4d78-803f-38990c078d9e')
|
@@ -1263,6 +1216,7 @@ module RubyEventStore
|
|
1263
1216
|
expect(repository.count(specification.from(event_id).result)).to eq(1)
|
1264
1217
|
expect(repository.count(specification.stream("Dummy").from(:head).result)).to eq(2)
|
1265
1218
|
expect(repository.count(specification.stream("Dummy").from(event_id).result)).to eq(1)
|
1219
|
+
expect(repository.count(specification.stream("Dummy").to(event_id).result)).to eq(0)
|
1266
1220
|
|
1267
1221
|
expect(repository.count(specification.limit(100).result)).to eq(5)
|
1268
1222
|
expect(repository.count(specification.limit(2).result)).to eq(2)
|