ruby_event_store 0.30.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +9 -1
- data/Makefile +15 -62
- data/lib/ruby_event_store/batch_enumerator.rb +15 -5
- data/lib/ruby_event_store/broker.rb +45 -0
- data/lib/ruby_event_store/client.rb +220 -130
- data/lib/ruby_event_store/composed_dispatcher.rb +24 -0
- data/lib/ruby_event_store/constants.rb +2 -0
- data/lib/ruby_event_store/correlated_commands.rb +42 -0
- data/lib/ruby_event_store/dispatcher.rb +20 -0
- data/lib/ruby_event_store/errors.rb +16 -16
- data/lib/ruby_event_store/event.rb +70 -14
- data/lib/ruby_event_store/expected_version.rb +2 -0
- data/lib/ruby_event_store/immediate_async_dispatcher.rb +17 -0
- data/lib/ruby_event_store/in_memory_repository.rb +45 -17
- data/lib/ruby_event_store/instrumented_dispatcher.rb +23 -0
- data/lib/ruby_event_store/instrumented_repository.rb +63 -0
- data/lib/ruby_event_store/link_by_metadata.rb +57 -0
- data/lib/ruby_event_store/mappers/default.rb +10 -26
- data/lib/ruby_event_store/mappers/encryption_key.rb +74 -0
- data/lib/ruby_event_store/mappers/encryption_mapper.rb +16 -0
- data/lib/ruby_event_store/mappers/forgotten_data.rb +30 -0
- data/lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb +34 -0
- data/lib/ruby_event_store/mappers/instrumented_mapper.rb +28 -0
- data/lib/ruby_event_store/mappers/json_mapper.rb +16 -0
- data/lib/ruby_event_store/mappers/null_mapper.rb +5 -8
- data/lib/ruby_event_store/mappers/pipeline.rb +31 -0
- data/lib/ruby_event_store/mappers/pipeline_mapper.rb +22 -0
- data/lib/ruby_event_store/mappers/protobuf.rb +13 -67
- data/lib/ruby_event_store/mappers/transformation/domain_event.rb +26 -0
- data/lib/ruby_event_store/mappers/transformation/encryption.rb +128 -0
- data/lib/ruby_event_store/mappers/transformation/event_class_remapper.rb +24 -0
- data/lib/ruby_event_store/mappers/transformation/item.rb +56 -0
- data/lib/ruby_event_store/mappers/transformation/proto_event.rb +17 -0
- data/lib/ruby_event_store/mappers/transformation/protobuf_encoder.rb +30 -0
- data/lib/ruby_event_store/mappers/transformation/protobuf_nested_struct_metadata.rb +30 -0
- data/lib/ruby_event_store/mappers/transformation/serialization.rb +34 -0
- data/lib/ruby_event_store/mappers/transformation/serialized_record.rb +27 -0
- data/lib/ruby_event_store/mappers/transformation/stringify_metadata_keys.rb +24 -0
- data/lib/ruby_event_store/mappers/transformation/symbolize_metadata_keys.rb +24 -0
- data/lib/ruby_event_store/metadata.rb +4 -2
- data/lib/ruby_event_store/projection.rb +34 -12
- data/lib/ruby_event_store/serialized_record.rb +3 -1
- data/lib/ruby_event_store/spec/broker_lint.rb +92 -0
- data/lib/ruby_event_store/spec/dispatcher_lint.rb +4 -36
- data/lib/ruby_event_store/spec/event_lint.rb +71 -0
- data/lib/ruby_event_store/spec/event_repository_lint.rb +1092 -962
- data/lib/ruby_event_store/spec/mapper_lint.rb +17 -0
- data/lib/ruby_event_store/spec/scheduler_lint.rb +9 -0
- data/lib/ruby_event_store/spec/subscriptions_lint.rb +111 -0
- data/lib/ruby_event_store/specification.rb +201 -56
- data/lib/ruby_event_store/specification_reader.rb +43 -0
- data/lib/ruby_event_store/specification_result.rb +212 -0
- data/lib/ruby_event_store/stream.rb +2 -0
- data/lib/ruby_event_store/subscriptions.rb +110 -0
- data/lib/ruby_event_store/transform_keys.rb +31 -0
- data/lib/ruby_event_store/version.rb +3 -1
- data/lib/ruby_event_store.rb +34 -4
- data/ruby_event_store.gemspec +1 -10
- metadata +47 -126
- data/exe/res-deprecated-read-api-migrator +0 -19
- data/lib/ruby_event_store/deprecated_read_api_rewriter.rb +0 -67
- data/lib/ruby_event_store/deprecated_read_api_runner.rb +0 -64
- data/lib/ruby_event_store/deprecations.rb +0 -7
- data/lib/ruby_event_store/pub_sub/broker.rb +0 -73
- data/lib/ruby_event_store/pub_sub/dispatcher.rb +0 -25
- data/lib/ruby_event_store/spec/event_broker_lint.rb +0 -211
@@ -1,1102 +1,1232 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
event_id: event_id,
|
10
|
-
data: data,
|
11
|
-
metadata: metadata,
|
12
|
-
event_type: event_type,
|
1
|
+
module RubyEventStore
|
2
|
+
# @private
|
3
|
+
class SRecord
|
4
|
+
def self.new(
|
5
|
+
event_id: SecureRandom.uuid,
|
6
|
+
data: '{}',
|
7
|
+
metadata: '{}',
|
8
|
+
event_type: 'SRecordTestEvent'
|
13
9
|
)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
let(:global_stream) { RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM) }
|
22
|
-
let(:stream) { RubyEventStore::Stream.new(SecureRandom.uuid) }
|
23
|
-
let(:stream_flow) { RubyEventStore::Stream.new('flow') }
|
24
|
-
let(:stream_other) { RubyEventStore::Stream.new('other') }
|
25
|
-
let(:stream_test) { RubyEventStore::Stream.new('test') }
|
26
|
-
let(:version_none) { RubyEventStore::ExpectedVersion.none }
|
27
|
-
let(:version_auto) { RubyEventStore::ExpectedVersion.auto }
|
28
|
-
let(:version_any) { RubyEventStore::ExpectedVersion.any }
|
29
|
-
let(:version_0) { RubyEventStore::ExpectedVersion.new(0) }
|
30
|
-
let(:version_1) { RubyEventStore::ExpectedVersion.new(1) }
|
31
|
-
let(:version_2) { RubyEventStore::ExpectedVersion.new(2) }
|
32
|
-
let(:version_3) { RubyEventStore::ExpectedVersion.new(3) }
|
33
|
-
|
34
|
-
def read_stream_events_forward(repository, stream)
|
35
|
-
repository.read(
|
36
|
-
specification
|
37
|
-
.stream(stream.name)
|
38
|
-
.result
|
39
|
-
).to_a
|
40
|
-
end
|
41
|
-
|
42
|
-
def read_stream_events_backward(repository, stream)
|
43
|
-
repository.read(
|
44
|
-
specification
|
45
|
-
.stream(stream.name)
|
46
|
-
.backward
|
47
|
-
.result
|
48
|
-
).to_a
|
49
|
-
end
|
50
|
-
|
51
|
-
def read_events_forward(repository, stream, start, count)
|
52
|
-
repository.read(
|
53
|
-
specification
|
54
|
-
.stream(stream.name)
|
55
|
-
.from(start)
|
56
|
-
.limit(count)
|
57
|
-
.result
|
58
|
-
).to_a
|
10
|
+
SerializedRecord.new(
|
11
|
+
event_id: event_id,
|
12
|
+
data: data,
|
13
|
+
metadata: metadata,
|
14
|
+
event_type: event_type,
|
15
|
+
)
|
16
|
+
end
|
59
17
|
end
|
60
18
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
.result
|
69
|
-
).to_a
|
70
|
-
end
|
19
|
+
# @private
|
20
|
+
Type1 = Class.new(RubyEventStore::Event)
|
21
|
+
# @private
|
22
|
+
Type2 = Class.new(RubyEventStore::Event)
|
23
|
+
# @private
|
24
|
+
Type3 = Class.new(RubyEventStore::Event)
|
25
|
+
end
|
71
26
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
.
|
76
|
-
|
77
|
-
|
78
|
-
).
|
79
|
-
|
27
|
+
module RubyEventStore
|
28
|
+
RSpec.shared_examples :event_repository do |repository_class, rescuable_concurrency_test_errors = []|
|
29
|
+
let(:repository) { subject || repository_class.new }
|
30
|
+
let(:mapper) { Mappers::NullMapper.new }
|
31
|
+
let(:specification) { Specification.new(SpecificationReader.new(repository, mapper)) }
|
32
|
+
let(:global_stream) { Stream.new(GLOBAL_STREAM) }
|
33
|
+
let(:stream) { Stream.new(SecureRandom.uuid) }
|
34
|
+
let(:stream_flow) { Stream.new('flow') }
|
35
|
+
let(:stream_other) { Stream.new('other') }
|
36
|
+
let(:stream_test) { Stream.new('test') }
|
37
|
+
let(:version_none) { ExpectedVersion.none }
|
38
|
+
let(:version_auto) { ExpectedVersion.auto }
|
39
|
+
let(:version_any) { ExpectedVersion.any }
|
40
|
+
let(:version_0) { ExpectedVersion.new(0) }
|
41
|
+
let(:version_1) { ExpectedVersion.new(1) }
|
42
|
+
let(:version_2) { ExpectedVersion.new(2) }
|
43
|
+
let(:version_3) { ExpectedVersion.new(3) }
|
44
|
+
|
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
|
80
52
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
.from(start)
|
85
|
-
.limit(count)
|
86
|
-
.backward
|
87
|
-
.result
|
88
|
-
).to_a
|
89
|
-
end
|
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
|
90
56
|
|
91
|
-
|
92
|
-
|
93
|
-
|
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)
|
59
|
+
end
|
94
60
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
append_to_stream(event = SRecord.new, stream, version_0)
|
99
|
-
end
|
61
|
+
it 'just created is empty' do
|
62
|
+
expect(read_events_forward(repository)).to be_empty
|
63
|
+
end
|
100
64
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
append_to_stream([event0, event1], stream, version_none).
|
107
|
-
link_to_stream(event0.event_id, stream_flow, version_none).
|
108
|
-
link_to_stream(event1.event_id, stream_flow, version_0)
|
109
|
-
end
|
65
|
+
specify 'append_to_stream returns self' do
|
66
|
+
repository
|
67
|
+
.append_to_stream(event = SRecord.new, stream, version_none)
|
68
|
+
.append_to_stream(event = SRecord.new, stream, version_0)
|
69
|
+
end
|
110
70
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
71
|
+
specify 'link_to_stream returns self' do
|
72
|
+
event0 = SRecord.new
|
73
|
+
event1 = SRecord.new
|
74
|
+
repository
|
75
|
+
.append_to_stream([event0, event1], stream, version_none)
|
76
|
+
.link_to_stream(event0.event_id, stream_flow, version_none)
|
77
|
+
.link_to_stream(event1.event_id, stream_flow, version_0)
|
78
|
+
end
|
117
79
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
80
|
+
specify 'adds an initial event to a new stream' do
|
81
|
+
repository.append_to_stream(event = SRecord.new, stream, version_none)
|
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
|
85
|
+
end
|
123
86
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
87
|
+
specify 'links an initial event to a new stream' do
|
88
|
+
repository
|
89
|
+
.append_to_stream(event = SRecord.new, stream, version_none)
|
90
|
+
.link_to_stream(event.event_id, stream_flow, version_none)
|
129
91
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
expect(read_all_streams_forward(repository, :head, 2)).to eq([event0, event1])
|
136
|
-
expect(read_stream_events_forward(repository, stream)).to eq([event0, event1])
|
137
|
-
end
|
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
|
96
|
+
end
|
138
97
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
event0
|
146
|
-
|
147
|
-
], stream_flow, version_none)
|
148
|
-
expect(read_all_streams_forward(repository, :head, 2)).to eq([event0, event1])
|
149
|
-
expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1])
|
150
|
-
end
|
98
|
+
specify 'adds multiple initial events to a new stream' do
|
99
|
+
repository.append_to_stream([
|
100
|
+
event0 = SRecord.new,
|
101
|
+
event1 = SRecord.new,
|
102
|
+
], stream, version_none)
|
103
|
+
expect(read_events_forward(repository, count: 2)).to eq([event0, event1])
|
104
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1])
|
105
|
+
end
|
151
106
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
107
|
+
specify 'links multiple initial events to a new stream' do
|
108
|
+
repository.append_to_stream([
|
109
|
+
event0 = SRecord.new,
|
110
|
+
event1 = SRecord.new,
|
111
|
+
], stream, version_none).link_to_stream([
|
112
|
+
event0.event_id,
|
113
|
+
event1.event_id,
|
114
|
+
], stream_flow, version_none)
|
115
|
+
expect(read_events_forward(repository, count: 2)).to eq([event0, event1])
|
116
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1])
|
117
|
+
end
|
164
118
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
event0
|
175
|
-
|
176
|
-
|
177
|
-
expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1, event2, event3])
|
178
|
-
expect(read_stream_events_forward(repository, stream_flow)).to eq([event2, event3, event0, event1])
|
179
|
-
end
|
119
|
+
specify 'correct expected version on second write' do
|
120
|
+
repository.append_to_stream([
|
121
|
+
event0 = SRecord.new,
|
122
|
+
event1 = SRecord.new,
|
123
|
+
], stream, version_none)
|
124
|
+
repository.append_to_stream([
|
125
|
+
event2 = SRecord.new,
|
126
|
+
event3 = SRecord.new,
|
127
|
+
], stream, version_1)
|
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])
|
130
|
+
end
|
180
131
|
|
181
|
-
|
182
|
-
repository.append_to_stream([
|
183
|
-
event0 = SRecord.new,
|
184
|
-
event1 = SRecord.new,
|
185
|
-
], stream, version_none)
|
186
|
-
expect do
|
132
|
+
specify 'correct expected version on second link' do
|
187
133
|
repository.append_to_stream([
|
134
|
+
event0 = SRecord.new,
|
135
|
+
event1 = SRecord.new,
|
136
|
+
], stream, version_none).append_to_stream([
|
188
137
|
event2 = SRecord.new,
|
189
138
|
event3 = SRecord.new,
|
190
|
-
],
|
191
|
-
|
139
|
+
], stream_flow, version_none).link_to_stream([
|
140
|
+
event0.event_id,
|
141
|
+
event1.event_id,
|
142
|
+
], stream_flow, version_1)
|
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])
|
145
|
+
end
|
192
146
|
|
193
|
-
|
194
|
-
|
195
|
-
|
147
|
+
specify 'incorrect expected version on second write' do
|
148
|
+
repository.append_to_stream([
|
149
|
+
event0 = SRecord.new,
|
150
|
+
event1 = SRecord.new,
|
151
|
+
], stream, version_none)
|
152
|
+
expect do
|
153
|
+
repository.append_to_stream([
|
154
|
+
event2 = SRecord.new,
|
155
|
+
event3 = SRecord.new,
|
156
|
+
], stream, version_0)
|
157
|
+
end.to raise_error(WrongExpectedEventVersion)
|
158
|
+
|
159
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1])
|
160
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1])
|
161
|
+
end
|
196
162
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
163
|
+
specify 'incorrect expected version on second link' do
|
164
|
+
repository.append_to_stream([
|
165
|
+
event0 = SRecord.new,
|
166
|
+
event1 = SRecord.new,
|
167
|
+
], stream, version_none)
|
168
|
+
repository.append_to_stream([
|
169
|
+
event2 = SRecord.new,
|
170
|
+
event3 = SRecord.new,
|
171
|
+
], stream_other, version_none)
|
172
|
+
expect do
|
173
|
+
repository.link_to_stream([
|
174
|
+
event2.event_id,
|
175
|
+
event3.event_id,
|
176
|
+
], stream, version_0)
|
177
|
+
end.to raise_error(WrongExpectedEventVersion)
|
178
|
+
|
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])
|
181
|
+
end
|
213
182
|
|
214
|
-
|
215
|
-
|
216
|
-
|
183
|
+
specify ':none on first and subsequent write' do
|
184
|
+
repository.append_to_stream([
|
185
|
+
eventA = SRecord.new,
|
186
|
+
], stream, version_none)
|
187
|
+
expect do
|
188
|
+
repository.append_to_stream([
|
189
|
+
eventB = SRecord.new,
|
190
|
+
], stream, version_none)
|
191
|
+
end.to raise_error(WrongExpectedEventVersion)
|
192
|
+
expect(read_events_forward(repository, count: 1)).to eq([eventA])
|
193
|
+
expect(read_events_forward(repository, stream)).to eq([eventA])
|
194
|
+
end
|
217
195
|
|
218
|
-
|
219
|
-
repository.append_to_stream([
|
220
|
-
eventA = SRecord.new,
|
221
|
-
], stream, version_none)
|
222
|
-
expect do
|
196
|
+
specify ':none on first and subsequent link' do
|
223
197
|
repository.append_to_stream([
|
198
|
+
eventA = SRecord.new,
|
224
199
|
eventB = SRecord.new,
|
225
200
|
], stream, version_none)
|
226
|
-
end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
|
227
|
-
expect(read_all_streams_forward(repository, :head, 1)).to eq([eventA])
|
228
|
-
expect(read_stream_events_forward(repository, stream)).to eq([eventA])
|
229
|
-
end
|
230
|
-
|
231
|
-
specify ':none on first and subsequent link' do
|
232
|
-
skip unless test_link_events_to_stream
|
233
|
-
repository.append_to_stream([
|
234
|
-
eventA = SRecord.new,
|
235
|
-
eventB = SRecord.new,
|
236
|
-
], stream, version_none)
|
237
201
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
202
|
+
repository.link_to_stream([eventA.event_id], stream_flow, version_none)
|
203
|
+
expect do
|
204
|
+
repository.link_to_stream([eventB.event_id], stream_flow, version_none)
|
205
|
+
end.to raise_error(WrongExpectedEventVersion)
|
242
206
|
|
243
|
-
|
244
|
-
|
245
|
-
|
207
|
+
expect(read_events_forward(repository, count: 1)).to eq([eventA])
|
208
|
+
expect(read_events_forward(repository, stream_flow)).to eq([eventA])
|
209
|
+
end
|
246
210
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
211
|
+
specify ':any allows stream with best-effort order and no guarantee' do
|
212
|
+
repository.append_to_stream([
|
213
|
+
event0 = SRecord.new,
|
214
|
+
event1 = SRecord.new,
|
215
|
+
], stream, version_any)
|
216
|
+
repository.append_to_stream([
|
217
|
+
event2 = SRecord.new,
|
218
|
+
event3 = SRecord.new,
|
219
|
+
], stream, version_any)
|
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]))
|
222
|
+
end
|
259
223
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
], stream, version_any)
|
268
|
-
|
269
|
-
repository.link_to_stream([
|
270
|
-
event0.event_id, event1.event_id,
|
271
|
-
], stream_flow, version_any)
|
272
|
-
repository.link_to_stream([
|
273
|
-
event2.event_id, event3.event_id,
|
274
|
-
], stream_flow, version_any)
|
275
|
-
|
276
|
-
expect(read_all_streams_forward(repository, :head, 4).to_set).to eq(Set.new([event0, event1, event2, event3]))
|
277
|
-
expect(read_stream_events_forward(repository, stream_flow).to_set).to eq(Set.new([event0, event1, event2, event3]))
|
278
|
-
end
|
224
|
+
specify ':any allows linking in stream with best-effort order and no guarantee' do
|
225
|
+
repository.append_to_stream([
|
226
|
+
event0 = SRecord.new,
|
227
|
+
event1 = SRecord.new,
|
228
|
+
event2 = SRecord.new,
|
229
|
+
event3 = SRecord.new,
|
230
|
+
], stream, version_any)
|
279
231
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
], stream_other, version_auto)
|
287
|
-
repository.append_to_stream([
|
288
|
-
event0 = SRecord.new,
|
289
|
-
event1 = SRecord.new,
|
290
|
-
], stream, version_auto)
|
291
|
-
repository.append_to_stream([
|
292
|
-
event2 = SRecord.new,
|
293
|
-
event3 = SRecord.new,
|
294
|
-
], stream, version_1)
|
295
|
-
end
|
232
|
+
repository.link_to_stream([
|
233
|
+
event0.event_id, event1.event_id,
|
234
|
+
], stream_flow, version_any)
|
235
|
+
repository.link_to_stream([
|
236
|
+
event2.event_id, event3.event_id,
|
237
|
+
], stream_flow, version_any)
|
296
238
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
repository.append_to_stream([
|
301
|
-
eventA = SRecord.new,
|
302
|
-
eventB = SRecord.new,
|
303
|
-
eventC = SRecord.new,
|
304
|
-
], stream_other, version_auto)
|
305
|
-
repository.append_to_stream([
|
306
|
-
event0 = SRecord.new,
|
307
|
-
event1 = SRecord.new,
|
308
|
-
], stream, version_auto)
|
309
|
-
repository.link_to_stream([
|
310
|
-
eventA.event_id,
|
311
|
-
eventB.event_id,
|
312
|
-
eventC.event_id,
|
313
|
-
], stream, version_1)
|
314
|
-
end
|
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]))
|
241
|
+
end
|
315
242
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
243
|
+
specify ':auto queries for last position in given stream' do
|
244
|
+
repository.append_to_stream([
|
245
|
+
eventA = SRecord.new,
|
246
|
+
eventB = SRecord.new,
|
247
|
+
eventC = SRecord.new,
|
248
|
+
], stream_other, version_auto)
|
322
249
|
repository.append_to_stream([
|
250
|
+
event0 = SRecord.new,
|
323
251
|
event1 = SRecord.new,
|
324
|
-
], stream,
|
325
|
-
|
326
|
-
|
252
|
+
], stream, version_auto)
|
253
|
+
repository.append_to_stream([
|
254
|
+
event2 = SRecord.new,
|
255
|
+
event3 = SRecord.new,
|
256
|
+
], stream, version_1)
|
257
|
+
end
|
327
258
|
|
328
|
-
|
329
|
-
skip unless test_expected_version_auto
|
330
|
-
skip unless test_link_events_to_stream
|
331
|
-
repository.append_to_stream([
|
332
|
-
event0 = SRecord.new,
|
333
|
-
], stream_other, version_auto)
|
334
|
-
repository.link_to_stream([
|
335
|
-
event0.event_id,
|
336
|
-
], stream, version_auto)
|
337
|
-
expect do
|
259
|
+
specify ':auto queries for last position in given stream when linking' do
|
338
260
|
repository.append_to_stream([
|
261
|
+
eventA = SRecord.new,
|
262
|
+
eventB = SRecord.new,
|
263
|
+
eventC = SRecord.new,
|
264
|
+
], stream_other, version_auto)
|
265
|
+
repository.append_to_stream([
|
266
|
+
event0 = SRecord.new,
|
339
267
|
event1 = SRecord.new,
|
340
|
-
], stream,
|
341
|
-
|
342
|
-
|
268
|
+
], stream, version_auto)
|
269
|
+
repository.link_to_stream([
|
270
|
+
eventA.event_id,
|
271
|
+
eventB.event_id,
|
272
|
+
eventC.event_id,
|
273
|
+
], stream, version_1)
|
274
|
+
end
|
343
275
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
event3 = SRecord.new,
|
355
|
-
], stream, version_auto)
|
356
|
-
expect(read_all_streams_forward(repository, :head, 4)).to eq([
|
357
|
-
event0, event1,
|
358
|
-
event2, event3
|
359
|
-
])
|
360
|
-
expect(read_stream_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
|
361
|
-
end
|
276
|
+
specify ':auto starts from 0' do
|
277
|
+
repository.append_to_stream([
|
278
|
+
event0 = SRecord.new,
|
279
|
+
], stream, version_auto)
|
280
|
+
expect do
|
281
|
+
repository.append_to_stream([
|
282
|
+
event1 = SRecord.new,
|
283
|
+
], stream, version_none)
|
284
|
+
end.to raise_error(WrongExpectedEventVersion)
|
285
|
+
end
|
362
286
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
event2.event_id, event3.event_id,
|
377
|
-
], stream_flow, version_auto)
|
378
|
-
expect(read_all_streams_forward(repository, :head, 4)).to eq([
|
379
|
-
event0, event1,
|
380
|
-
event2, event3
|
381
|
-
])
|
382
|
-
expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1, event2, event3])
|
383
|
-
end
|
287
|
+
specify ':auto linking starts from 0' do
|
288
|
+
repository.append_to_stream([
|
289
|
+
event0 = SRecord.new,
|
290
|
+
], stream_other, version_auto)
|
291
|
+
repository.link_to_stream([
|
292
|
+
event0.event_id,
|
293
|
+
], stream, version_auto)
|
294
|
+
expect do
|
295
|
+
repository.append_to_stream([
|
296
|
+
event1 = SRecord.new,
|
297
|
+
], stream, version_none)
|
298
|
+
end.to raise_error(WrongExpectedEventVersion)
|
299
|
+
end
|
384
300
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
301
|
+
specify ':auto queries for last position and follows in incremental way' do
|
302
|
+
# It is expected that there is higher level lock
|
303
|
+
# So this query is safe from race conditions
|
304
|
+
repository.append_to_stream([
|
305
|
+
event0 = SRecord.new,
|
306
|
+
event1 = SRecord.new,
|
307
|
+
], stream, version_auto)
|
308
|
+
repository.append_to_stream([
|
309
|
+
event2 = SRecord.new,
|
310
|
+
event3 = SRecord.new,
|
311
|
+
], stream, version_auto)
|
312
|
+
expect(read_events_forward(repository, count: 4)).to eq([
|
313
|
+
event0, event1,
|
314
|
+
event2, event3
|
315
|
+
])
|
316
|
+
expect(read_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
|
317
|
+
end
|
398
318
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
319
|
+
specify ':auto queries for last position and follows in incremental way when linking' do
|
320
|
+
repository.append_to_stream([
|
321
|
+
event0 = SRecord.new,
|
322
|
+
event1 = SRecord.new,
|
323
|
+
event2 = SRecord.new,
|
324
|
+
event3 = SRecord.new,
|
325
|
+
], stream, version_auto)
|
326
|
+
repository.link_to_stream([
|
327
|
+
event0.event_id, event1.event_id,
|
328
|
+
], stream_flow, version_auto)
|
329
|
+
repository.link_to_stream([
|
330
|
+
event2.event_id, event3.event_id,
|
331
|
+
], stream_flow, version_auto)
|
332
|
+
expect(read_events_forward(repository, count: 4)).to eq([
|
333
|
+
event0, event1,
|
334
|
+
event2, event3
|
335
|
+
])
|
336
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1, event2, event3])
|
337
|
+
end
|
415
338
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
end
|
339
|
+
specify ':auto is compatible with manual expectation' do
|
340
|
+
repository.append_to_stream([
|
341
|
+
event0 = SRecord.new,
|
342
|
+
event1 = SRecord.new,
|
343
|
+
], stream, version_auto)
|
344
|
+
repository.append_to_stream([
|
345
|
+
event2 = SRecord.new,
|
346
|
+
event3 = SRecord.new,
|
347
|
+
], stream, version_1)
|
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])
|
350
|
+
end
|
429
351
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1])
|
445
|
-
end
|
352
|
+
specify ':auto is compatible with manual expectation when linking' do
|
353
|
+
repository.append_to_stream([
|
354
|
+
event0 = SRecord.new,
|
355
|
+
event1 = SRecord.new,
|
356
|
+
], stream, version_auto)
|
357
|
+
repository.link_to_stream([
|
358
|
+
event0.event_id,
|
359
|
+
], stream_flow, version_auto)
|
360
|
+
repository.link_to_stream([
|
361
|
+
event1.event_id,
|
362
|
+
], stream_flow, version_0)
|
363
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1,])
|
364
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1,])
|
365
|
+
end
|
446
366
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
367
|
+
specify 'manual is compatible with auto expectation' do
|
368
|
+
repository.append_to_stream([
|
369
|
+
event0 = SRecord.new,
|
370
|
+
event1 = SRecord.new,
|
371
|
+
], stream, version_none)
|
372
|
+
repository.append_to_stream([
|
373
|
+
event2 = SRecord.new,
|
374
|
+
event3 = SRecord.new,
|
375
|
+
], stream, version_auto)
|
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])
|
378
|
+
end
|
452
379
|
|
453
|
-
|
454
|
-
|
380
|
+
specify 'manual is compatible with auto expectation when linking' do
|
381
|
+
repository.append_to_stream([
|
382
|
+
event0 = SRecord.new,
|
383
|
+
event1 = SRecord.new,
|
384
|
+
], stream, version_auto)
|
385
|
+
repository.link_to_stream([
|
386
|
+
event0.event_id,
|
387
|
+
], stream_flow, version_none)
|
388
|
+
repository.link_to_stream([
|
389
|
+
event1.event_id,
|
390
|
+
], stream_flow, version_auto)
|
391
|
+
expect(read_events_forward(repository, count: 4)).to eq([event0, event1])
|
392
|
+
expect(read_events_forward(repository, stream_flow)).to eq([event0, event1])
|
393
|
+
end
|
455
394
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
395
|
+
specify 'unlimited concurrency for :any - everything should succeed', timeout: 10, mutant: false do
|
396
|
+
skip unless test_race_conditions_any
|
397
|
+
verify_conncurency_assumptions
|
398
|
+
begin
|
399
|
+
concurrency_level = 4
|
400
|
+
fail_occurred = false
|
401
|
+
wait_for_it = true
|
402
|
+
|
403
|
+
threads = concurrency_level.times.map do |i|
|
404
|
+
Thread.new do
|
405
|
+
true while wait_for_it
|
406
|
+
begin
|
407
|
+
100.times do |j|
|
408
|
+
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
409
|
+
repository.append_to_stream([
|
410
|
+
SRecord.new(event_id: eid),
|
411
|
+
], stream, version_any)
|
412
|
+
end
|
413
|
+
rescue WrongExpectedEventVersion
|
414
|
+
fail_occurred = true
|
465
415
|
end
|
466
|
-
rescue RubyEventStore::WrongExpectedEventVersion
|
467
|
-
fail_occurred = true
|
468
416
|
end
|
469
417
|
end
|
418
|
+
wait_for_it = false
|
419
|
+
threads.each(&:join)
|
420
|
+
expect(fail_occurred).to eq(false)
|
421
|
+
expect(read_events_forward(repository, stream).size).to eq(400)
|
422
|
+
events_in_stream = read_events_forward(repository, stream)
|
423
|
+
expect(events_in_stream.size).to eq(400)
|
424
|
+
events0 = events_in_stream.select do |ev|
|
425
|
+
ev.event_id.start_with?("0-")
|
426
|
+
end
|
427
|
+
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
428
|
+
ensure
|
429
|
+
cleanup_concurrency_test
|
470
430
|
end
|
471
|
-
wait_for_it = false
|
472
|
-
threads.each(&:join)
|
473
|
-
expect(fail_occurred).to eq(false)
|
474
|
-
expect(read_stream_events_forward(repository, stream).size).to eq(400)
|
475
|
-
events_in_stream = read_stream_events_forward(repository, stream)
|
476
|
-
expect(events_in_stream.size).to eq(400)
|
477
|
-
events0 = events_in_stream.select do |ev|
|
478
|
-
ev.event_id.start_with?("0-")
|
479
|
-
end
|
480
|
-
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
481
|
-
ensure
|
482
|
-
cleanup_concurrency_test
|
483
431
|
end
|
484
|
-
end
|
485
432
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
], stream, version_any)
|
433
|
+
specify 'unlimited concurrency for :any - everything should succeed when linking', timeout: 10, mutant: false do
|
434
|
+
skip unless test_race_conditions_any
|
435
|
+
verify_conncurency_assumptions
|
436
|
+
begin
|
437
|
+
concurrency_level = 4
|
438
|
+
fail_occurred = false
|
439
|
+
wait_for_it = true
|
440
|
+
|
441
|
+
concurrency_level.times.map do |i|
|
442
|
+
100.times do |j|
|
443
|
+
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
444
|
+
repository.append_to_stream([
|
445
|
+
SRecord.new(event_id: eid),
|
446
|
+
], stream, version_any)
|
447
|
+
end
|
502
448
|
end
|
503
|
-
end
|
504
449
|
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
450
|
+
threads = concurrency_level.times.map do |i|
|
451
|
+
Thread.new do
|
452
|
+
true while wait_for_it
|
453
|
+
begin
|
454
|
+
100.times do |j|
|
455
|
+
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
456
|
+
repository.link_to_stream(eid, stream_flow, version_any)
|
457
|
+
end
|
458
|
+
rescue WrongExpectedEventVersion
|
459
|
+
fail_occurred = true
|
512
460
|
end
|
513
|
-
rescue RubyEventStore::WrongExpectedEventVersion
|
514
|
-
fail_occurred = true
|
515
461
|
end
|
516
462
|
end
|
463
|
+
wait_for_it = false
|
464
|
+
threads.each(&:join)
|
465
|
+
expect(fail_occurred).to eq(false)
|
466
|
+
expect(read_events_forward(repository, stream_flow).size).to eq(400)
|
467
|
+
events_in_stream = read_events_forward(repository, stream_flow)
|
468
|
+
expect(events_in_stream.size).to eq(400)
|
469
|
+
events0 = events_in_stream.select do |ev|
|
470
|
+
ev.event_id.start_with?("0-")
|
471
|
+
end
|
472
|
+
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
473
|
+
ensure
|
474
|
+
cleanup_concurrency_test
|
517
475
|
end
|
518
|
-
wait_for_it = false
|
519
|
-
threads.each(&:join)
|
520
|
-
expect(fail_occurred).to eq(false)
|
521
|
-
expect(read_stream_events_forward(repository, stream_flow).size).to eq(400)
|
522
|
-
events_in_stream = read_stream_events_forward(repository, stream_flow)
|
523
|
-
expect(events_in_stream.size).to eq(400)
|
524
|
-
events0 = events_in_stream.select do |ev|
|
525
|
-
ev.event_id.start_with?("0-")
|
526
|
-
end
|
527
|
-
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
528
|
-
ensure
|
529
|
-
cleanup_concurrency_test
|
530
476
|
end
|
531
|
-
end
|
532
477
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
concurrency_level = 4
|
478
|
+
specify 'limited concurrency for :auto - some operations will fail without outside lock, stream is ordered', mutant: false do
|
479
|
+
skip unless test_race_conditions_auto
|
480
|
+
verify_conncurency_assumptions
|
481
|
+
begin
|
482
|
+
concurrency_level = 4
|
539
483
|
|
540
|
-
|
541
|
-
|
484
|
+
fail_occurred = 0
|
485
|
+
wait_for_it = true
|
542
486
|
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
487
|
+
threads = concurrency_level.times.map do |i|
|
488
|
+
Thread.new do
|
489
|
+
true while wait_for_it
|
490
|
+
100.times do |j|
|
491
|
+
begin
|
492
|
+
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
493
|
+
repository.append_to_stream([
|
494
|
+
SRecord.new(event_id: eid),
|
495
|
+
], stream, version_auto)
|
496
|
+
sleep(rand(concurrency_level) / 1000.0)
|
497
|
+
rescue WrongExpectedEventVersion, *rescuable_concurrency_test_errors
|
498
|
+
fail_occurred +=1
|
499
|
+
end
|
555
500
|
end
|
556
501
|
end
|
557
502
|
end
|
503
|
+
wait_for_it = false
|
504
|
+
threads.each(&:join)
|
505
|
+
expect(fail_occurred).to be > 0
|
506
|
+
events_in_stream = read_events_forward(repository, stream)
|
507
|
+
expect(events_in_stream.size).to be < 400
|
508
|
+
expect(events_in_stream.size).to be >= 100
|
509
|
+
events0 = events_in_stream.select do |ev|
|
510
|
+
ev.event_id.start_with?("0-")
|
511
|
+
end
|
512
|
+
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
513
|
+
additional_limited_concurrency_for_auto_check
|
514
|
+
ensure
|
515
|
+
cleanup_concurrency_test
|
558
516
|
end
|
559
|
-
wait_for_it = false
|
560
|
-
threads.each(&:join)
|
561
|
-
expect(fail_occurred).to be > 0
|
562
|
-
events_in_stream = read_stream_events_forward(repository, stream)
|
563
|
-
expect(events_in_stream.size).to be < 400
|
564
|
-
expect(events_in_stream.size).to be >= 100
|
565
|
-
events0 = events_in_stream.select do |ev|
|
566
|
-
ev.event_id.start_with?("0-")
|
567
|
-
end
|
568
|
-
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
569
|
-
additional_limited_concurrency_for_auto_check
|
570
|
-
ensure
|
571
|
-
cleanup_concurrency_test
|
572
517
|
end
|
573
|
-
end
|
574
518
|
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
SRecord.new(event_id: eid),
|
589
|
-
], stream_other, version_any)
|
519
|
+
specify 'limited concurrency for :auto - some operations will fail without outside lock, stream is ordered', mutant: false do
|
520
|
+
skip unless test_race_conditions_auto
|
521
|
+
verify_conncurency_assumptions
|
522
|
+
begin
|
523
|
+
concurrency_level = 4
|
524
|
+
|
525
|
+
concurrency_level.times.map do |i|
|
526
|
+
100.times do |j|
|
527
|
+
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
528
|
+
repository.append_to_stream([
|
529
|
+
SRecord.new(event_id: eid),
|
530
|
+
], stream_other, version_any)
|
531
|
+
end
|
590
532
|
end
|
591
|
-
end
|
592
533
|
|
593
|
-
|
594
|
-
|
534
|
+
fail_occurred = 0
|
535
|
+
wait_for_it = true
|
595
536
|
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
537
|
+
threads = concurrency_level.times.map do |i|
|
538
|
+
Thread.new do
|
539
|
+
true while wait_for_it
|
540
|
+
100.times do |j|
|
541
|
+
begin
|
542
|
+
eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
|
543
|
+
repository.link_to_stream(eid, stream, version_auto)
|
544
|
+
sleep(rand(concurrency_level) / 1000.0)
|
545
|
+
rescue WrongExpectedEventVersion, *rescuable_concurrency_test_errors
|
546
|
+
fail_occurred +=1
|
547
|
+
end
|
606
548
|
end
|
607
549
|
end
|
608
550
|
end
|
551
|
+
wait_for_it = false
|
552
|
+
threads.each(&:join)
|
553
|
+
expect(fail_occurred).to be > 0
|
554
|
+
events_in_stream = read_events_forward(repository, stream)
|
555
|
+
expect(events_in_stream.size).to be < 400
|
556
|
+
expect(events_in_stream.size).to be >= 100
|
557
|
+
events0 = events_in_stream.select do |ev|
|
558
|
+
ev.event_id.start_with?("0-")
|
559
|
+
end
|
560
|
+
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
561
|
+
additional_limited_concurrency_for_auto_check
|
562
|
+
ensure
|
563
|
+
cleanup_concurrency_test
|
609
564
|
end
|
610
|
-
wait_for_it = false
|
611
|
-
threads.each(&:join)
|
612
|
-
expect(fail_occurred).to be > 0
|
613
|
-
events_in_stream = read_stream_events_forward(repository, stream)
|
614
|
-
expect(events_in_stream.size).to be < 400
|
615
|
-
expect(events_in_stream.size).to be >= 100
|
616
|
-
events0 = events_in_stream.select do |ev|
|
617
|
-
ev.event_id.start_with?("0-")
|
618
|
-
end
|
619
|
-
expect(events0).to eq(events0.sort_by{|ev| ev.event_id })
|
620
|
-
additional_limited_concurrency_for_auto_check
|
621
|
-
ensure
|
622
|
-
cleanup_concurrency_test
|
623
565
|
end
|
624
|
-
end
|
625
566
|
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
567
|
+
it 'appended event is stored in given stream' do
|
568
|
+
expected_event = SRecord.new
|
569
|
+
repository.append_to_stream(expected_event, stream, version_any)
|
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
|
573
|
+
end
|
633
574
|
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
575
|
+
it 'data attributes are retrieved' do
|
576
|
+
event = SRecord.new(data: '{"order_id":3}')
|
577
|
+
repository.append_to_stream(event, stream, version_any)
|
578
|
+
retrieved_event = read_events_forward(repository, count: 1).first
|
579
|
+
expect(retrieved_event.data).to eq('{"order_id":3}')
|
580
|
+
end
|
640
581
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
582
|
+
it 'metadata attributes are retrieved' do
|
583
|
+
event = SRecord.new(metadata: '{"request_id":3}')
|
584
|
+
repository.append_to_stream(event, stream, version_any)
|
585
|
+
retrieved_event = read_events_forward(repository, count: 1).first
|
586
|
+
expect(retrieved_event.metadata).to eq('{"request_id":3}')
|
587
|
+
end
|
647
588
|
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
end
|
589
|
+
it 'data and metadata attributes are retrieved when linking' do
|
590
|
+
event = SRecord.new(
|
591
|
+
data: '{"order_id":3}',
|
592
|
+
metadata: '{"request_id":4}',
|
593
|
+
)
|
594
|
+
repository
|
595
|
+
.append_to_stream(event, stream, version_any)
|
596
|
+
.link_to_stream(event.event_id, stream_flow, version_any)
|
597
|
+
retrieved_event = read_events_forward(repository, stream_flow).first
|
598
|
+
expect(retrieved_event.metadata).to eq('{"request_id":4}')
|
599
|
+
expect(retrieved_event.data).to eq('{"order_id":3}')
|
600
|
+
expect(event).to eq(retrieved_event)
|
601
|
+
end
|
662
602
|
|
663
|
-
|
664
|
-
|
665
|
-
|
603
|
+
it 'does not have deleted streams' do
|
604
|
+
repository.append_to_stream(e1 = SRecord.new, stream, version_none)
|
605
|
+
repository.append_to_stream(e2 = SRecord.new, stream_other, version_none)
|
666
606
|
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
607
|
+
repository.delete_stream(stream)
|
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])
|
611
|
+
end
|
672
612
|
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
link_to_stream(e1.event_id, stream_flow, version_none)
|
613
|
+
it 'does not have deleted streams with linked events' do
|
614
|
+
repository
|
615
|
+
.append_to_stream(e1 = SRecord.new, stream, version_none)
|
616
|
+
.link_to_stream(e1.event_id, stream_flow, version_none)
|
678
617
|
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
618
|
+
repository.delete_stream(stream_flow)
|
619
|
+
expect(read_events_forward(repository, stream_flow)).to be_empty
|
620
|
+
expect(read_events_forward(repository, count: 10)).to eq([e1])
|
621
|
+
end
|
683
622
|
|
684
|
-
|
685
|
-
|
686
|
-
|
623
|
+
it 'has or has not domain event' do
|
624
|
+
just_an_id = 'd5c134c2-db65-4e87-b6ea-d196f8f1a292'
|
625
|
+
repository.append_to_stream(SRecord.new(event_id: just_an_id), stream, version_none)
|
687
626
|
|
688
|
-
|
689
|
-
|
690
|
-
|
627
|
+
expect(repository.has_event?(just_an_id)).to be_truthy
|
628
|
+
expect(repository.has_event?(just_an_id.clone)).to be_truthy
|
629
|
+
expect(repository.has_event?('any other id')).to be_falsey
|
691
630
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
631
|
+
repository.delete_stream(stream)
|
632
|
+
expect(repository.has_event?(just_an_id)).to be_truthy
|
633
|
+
expect(repository.has_event?(just_an_id.clone)).to be_truthy
|
634
|
+
end
|
696
635
|
|
697
|
-
|
698
|
-
|
699
|
-
|
636
|
+
it 'knows last event in stream' do
|
637
|
+
repository.append_to_stream(a =SRecord.new(event_id: '00000000-0000-0000-0000-000000000001'), stream, version_none)
|
638
|
+
repository.append_to_stream(b = SRecord.new(event_id: '00000000-0000-0000-0000-000000000002'), stream, version_0)
|
700
639
|
|
701
|
-
|
702
|
-
|
703
|
-
|
640
|
+
expect(repository.last_stream_event(stream)).to eq(b)
|
641
|
+
expect(repository.last_stream_event(stream_other)).to be_nil
|
642
|
+
end
|
704
643
|
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
version_none
|
713
|
-
|
714
|
-
|
715
|
-
end
|
644
|
+
it 'knows last event in stream when linked' do
|
645
|
+
repository.append_to_stream([
|
646
|
+
e0 = SRecord.new(event_id: '00000000-0000-0000-0000-000000000001'),
|
647
|
+
e1 = SRecord.new(event_id: '00000000-0000-0000-0000-000000000002'),
|
648
|
+
],
|
649
|
+
stream,
|
650
|
+
version_none
|
651
|
+
).link_to_stream([e1.event_id, e0.event_id], stream_flow, version_none)
|
652
|
+
expect(repository.last_stream_event(stream_flow)).to eq(e0)
|
653
|
+
end
|
716
654
|
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
655
|
+
it 'reads batch of events from stream forward & backward' do
|
656
|
+
events = %w[
|
657
|
+
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
658
|
+
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
659
|
+
6a54dd21-f9d8-4857-a195-f5588d9e406c
|
660
|
+
0e50a9cd-f981-4e39-93d5-697fc7285b98
|
661
|
+
d85589bc-b993-41d4-812f-fc631d9185d5
|
662
|
+
96bdacda-77dd-4d7d-973d-cbdaa5842855
|
663
|
+
94688199-e6b7-4180-bf8e-825b6808e6cc
|
664
|
+
68fab040-741e-4bc2-9cca-5b8855b0ca19
|
665
|
+
ab60114c-011d-4d58-ab31-7ba65d99975e
|
666
|
+
868cac42-3d19-4b39-84e8-cd32d65c2445
|
667
|
+
].map { |id| SRecord.new(event_id: id) }
|
668
|
+
repository.append_to_stream(SRecord.new, stream_other, version_none)
|
669
|
+
events.each.with_index do |event, index|
|
670
|
+
repository.append_to_stream(event, stream, ExpectedVersion.new(index - 1))
|
671
|
+
end
|
672
|
+
repository.append_to_stream(SRecord.new, stream_other, version_0)
|
673
|
+
|
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])
|
681
|
+
|
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)
|
688
|
+
end
|
747
689
|
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
690
|
+
it 'reads batch of linked events from stream forward & backward' do
|
691
|
+
events = %w[
|
692
|
+
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
693
|
+
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
694
|
+
6a54dd21-f9d8-4857-a195-f5588d9e406c
|
695
|
+
0e50a9cd-f981-4e39-93d5-697fc7285b98
|
696
|
+
d85589bc-b993-41d4-812f-fc631d9185d5
|
697
|
+
96bdacda-77dd-4d7d-973d-cbdaa5842855
|
698
|
+
94688199-e6b7-4180-bf8e-825b6808e6cc
|
699
|
+
68fab040-741e-4bc2-9cca-5b8855b0ca19
|
700
|
+
ab60114c-011d-4d58-ab31-7ba65d99975e
|
701
|
+
868cac42-3d19-4b39-84e8-cd32d65c2445
|
702
|
+
].map { |id| SRecord.new(event_id: id) }
|
703
|
+
repository.append_to_stream(SRecord.new, stream_other, version_none)
|
704
|
+
events.each.with_index do |event, index|
|
705
|
+
repository
|
706
|
+
.append_to_stream(event, stream, ExpectedVersion.new(index - 1))
|
707
|
+
.link_to_stream(event.event_id, stream_flow, ExpectedVersion.new(index - 1))
|
708
|
+
end
|
709
|
+
repository.append_to_stream(SRecord.new, stream_other, version_0)
|
710
|
+
|
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])
|
717
|
+
|
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)
|
724
|
+
end
|
780
725
|
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
726
|
+
it 'reads all stream events forward & backward' do
|
727
|
+
s1 = stream
|
728
|
+
s2 = stream_other
|
729
|
+
repository
|
730
|
+
.append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, version_none)
|
731
|
+
.append_to_stream(b = SRecord.new(event_id: '34f88aca-aaba-4ca0-9256-8017b47528c5'), s2, version_none)
|
732
|
+
.append_to_stream(c = SRecord.new(event_id: '8e61c864-ceae-4684-8726-97c34eb8fc4f'), s1, version_0)
|
733
|
+
.append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s2, version_0)
|
734
|
+
.append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s2, version_1)
|
735
|
+
|
736
|
+
expect(read_events_forward(repository, s1)).to eq [a,c]
|
737
|
+
expect(read_events_backward(repository, s1)).to eq [c,a]
|
738
|
+
end
|
794
739
|
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
end
|
740
|
+
it 'reads all stream linked events forward & backward' do
|
741
|
+
s1, fs1, fs2 = stream, stream_flow, stream_other
|
742
|
+
repository
|
743
|
+
.append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, version_none)
|
744
|
+
.append_to_stream(b = SRecord.new(event_id: '34f88aca-aaba-4ca0-9256-8017b47528c5'), s1, version_0)
|
745
|
+
.append_to_stream(c = SRecord.new(event_id: '8e61c864-ceae-4684-8726-97c34eb8fc4f'), s1, version_1)
|
746
|
+
.append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s1, version_2)
|
747
|
+
.append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s1, version_3)
|
748
|
+
.link_to_stream('7010d298-ab69-4bb1-9251-f3466b5d1282', fs1, version_none)
|
749
|
+
.link_to_stream('34f88aca-aaba-4ca0-9256-8017b47528c5', fs2, version_none)
|
750
|
+
.link_to_stream('8e61c864-ceae-4684-8726-97c34eb8fc4f', fs1, version_0)
|
751
|
+
.link_to_stream('30963ed9-6349-450b-ac9b-8ea50115b3bd', fs2, version_0)
|
752
|
+
.link_to_stream('5bdc58b7-e8a7-4621-afd6-ccb828d72457', fs2, version_1)
|
753
|
+
|
754
|
+
expect(read_events_forward(repository, fs1)).to eq [a,c]
|
755
|
+
expect(read_events_backward(repository, fs1)).to eq [c,a]
|
756
|
+
end
|
813
757
|
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
expect(read_all_streams_forward(repository, :head, 3)).to eq(events.first(3))
|
832
|
-
expect(read_all_streams_forward(repository, :head, 100)).to eq(events)
|
833
|
-
expect(read_all_streams_forward(repository, events[4].event_id, 4)).to eq(events[5..8])
|
834
|
-
expect(read_all_streams_forward(repository, events[4].event_id, 100)).to eq(events[5..9])
|
835
|
-
|
836
|
-
expect(read_all_streams_backward(repository, :head, 3)).to eq(events.last(3).reverse)
|
837
|
-
expect(read_all_streams_backward(repository, :head, 100)).to eq(events.reverse)
|
838
|
-
expect(read_all_streams_backward(repository, events[4].event_id, 4)).to eq(events.first(4).reverse)
|
839
|
-
expect(read_all_streams_backward(repository, events[4].event_id, 100)).to eq(events.first(4).reverse)
|
840
|
-
end
|
758
|
+
it 'reads batch of events from all streams forward & backward' do
|
759
|
+
events = %w[
|
760
|
+
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
761
|
+
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
762
|
+
6a54dd21-f9d8-4857-a195-f5588d9e406c
|
763
|
+
0e50a9cd-f981-4e39-93d5-697fc7285b98
|
764
|
+
d85589bc-b993-41d4-812f-fc631d9185d5
|
765
|
+
96bdacda-77dd-4d7d-973d-cbdaa5842855
|
766
|
+
94688199-e6b7-4180-bf8e-825b6808e6cc
|
767
|
+
68fab040-741e-4bc2-9cca-5b8855b0ca19
|
768
|
+
ab60114c-011d-4d58-ab31-7ba65d99975e
|
769
|
+
868cac42-3d19-4b39-84e8-cd32d65c2445
|
770
|
+
].map { |id| SRecord.new(event_id: id) }
|
771
|
+
events.each do |ev|
|
772
|
+
repository.append_to_stream(ev, Stream.new(SecureRandom.uuid), version_none)
|
773
|
+
end
|
841
774
|
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
events.each do |ev|
|
857
|
-
repository.
|
858
|
-
append_to_stream(ev, RubyEventStore::Stream.new(SecureRandom.uuid), version_none).
|
859
|
-
link_to_stream(ev.event_id, RubyEventStore::Stream.new(SecureRandom.uuid), version_none)
|
860
|
-
end
|
861
|
-
|
862
|
-
expect(read_all_streams_forward(repository, :head, 3)).to eq(events.first(3))
|
863
|
-
expect(read_all_streams_forward(repository, :head, 100)).to eq(events)
|
864
|
-
expect(read_all_streams_forward(repository, events[4].event_id, 4)).to eq(events[5..8])
|
865
|
-
expect(read_all_streams_forward(repository, events[4].event_id, 100)).to eq(events[5..9])
|
866
|
-
|
867
|
-
expect(read_all_streams_backward(repository, :head, 3)).to eq(events.last(3).reverse)
|
868
|
-
expect(read_all_streams_backward(repository, :head, 100)).to eq(events.reverse)
|
869
|
-
expect(read_all_streams_backward(repository, events[4].event_id, 4)).to eq(events.first(4).reverse)
|
870
|
-
expect(read_all_streams_backward(repository, events[4].event_id, 100)).to eq(events.first(4).reverse)
|
871
|
-
end
|
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])
|
781
|
+
|
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)
|
788
|
+
end
|
872
789
|
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
790
|
+
it 'linked events do not affect reading from all streams - no duplicates' do
|
791
|
+
events = %w[
|
792
|
+
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
793
|
+
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
794
|
+
6a54dd21-f9d8-4857-a195-f5588d9e406c
|
795
|
+
0e50a9cd-f981-4e39-93d5-697fc7285b98
|
796
|
+
d85589bc-b993-41d4-812f-fc631d9185d5
|
797
|
+
96bdacda-77dd-4d7d-973d-cbdaa5842855
|
798
|
+
94688199-e6b7-4180-bf8e-825b6808e6cc
|
799
|
+
68fab040-741e-4bc2-9cca-5b8855b0ca19
|
800
|
+
ab60114c-011d-4d58-ab31-7ba65d99975e
|
801
|
+
868cac42-3d19-4b39-84e8-cd32d65c2445
|
802
|
+
].map { |id| SRecord.new(event_id: id) }
|
803
|
+
events.each do |ev|
|
804
|
+
repository
|
805
|
+
.append_to_stream(ev, Stream.new(SecureRandom.uuid), version_none)
|
806
|
+
.link_to_stream(ev.event_id, Stream.new(SecureRandom.uuid), version_none)
|
807
|
+
end
|
880
808
|
|
881
|
-
|
882
|
-
|
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])
|
815
|
+
|
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)
|
822
|
+
end
|
883
823
|
|
884
|
-
|
885
|
-
|
886
|
-
|
824
|
+
it 'reads events different uuid object but same content' do
|
825
|
+
events = %w[
|
826
|
+
96c920b1-cdd0-40f4-907c-861b9fff7d02
|
827
|
+
56404f79-0ba0-4aa0-8524-dc3436368ca0
|
828
|
+
].map{|id| SRecord.new(event_id: id) }
|
829
|
+
repository.append_to_stream(events.first, stream, version_none)
|
830
|
+
repository.append_to_stream(events.last, stream, version_0)
|
831
|
+
|
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])
|
836
|
+
|
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])
|
841
|
+
end
|
887
842
|
|
888
|
-
|
889
|
-
repository.append_to_stream(
|
890
|
-
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
891
|
-
stream,
|
892
|
-
version_none
|
893
|
-
)
|
894
|
-
expect do
|
843
|
+
it 'does not allow same event twice in a stream' do
|
895
844
|
repository.append_to_stream(
|
896
845
|
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
897
846
|
stream,
|
898
|
-
|
847
|
+
version_none
|
899
848
|
)
|
900
|
-
|
901
|
-
|
849
|
+
expect do
|
850
|
+
repository.append_to_stream(
|
851
|
+
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
852
|
+
stream,
|
853
|
+
version_0
|
854
|
+
)
|
855
|
+
end.to raise_error(EventDuplicatedInStream)
|
856
|
+
end
|
902
857
|
|
903
|
-
|
904
|
-
repository.append_to_stream(
|
905
|
-
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
906
|
-
stream,
|
907
|
-
version_none
|
908
|
-
)
|
909
|
-
expect do
|
858
|
+
it 'does not allow same event twice' do
|
910
859
|
repository.append_to_stream(
|
911
860
|
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
912
|
-
|
861
|
+
stream,
|
913
862
|
version_none
|
914
863
|
)
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
version_none
|
924
|
-
).link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", stream_flow, version_none)
|
925
|
-
expect do
|
926
|
-
repository.link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", stream_flow, version_0)
|
927
|
-
end.to raise_error(RubyEventStore::EventDuplicatedInStream)
|
928
|
-
end
|
864
|
+
expect do
|
865
|
+
repository.append_to_stream(
|
866
|
+
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
867
|
+
stream_other,
|
868
|
+
version_none
|
869
|
+
)
|
870
|
+
end.to raise_error(EventDuplicatedInStream)
|
871
|
+
end
|
929
872
|
|
930
|
-
|
931
|
-
|
932
|
-
|
873
|
+
it 'does not allow linking same event twice in a stream' do
|
874
|
+
repository.append_to_stream([
|
875
|
+
SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
|
876
|
+
], stream,
|
877
|
+
version_none
|
878
|
+
).link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", stream_flow, version_none)
|
879
|
+
expect do
|
880
|
+
repository.link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", stream_flow, version_0)
|
881
|
+
end.to raise_error(EventDuplicatedInStream)
|
882
|
+
end
|
933
883
|
|
934
|
-
|
935
|
-
|
884
|
+
it 'allows appending to GLOBAL_STREAM explicitly' do
|
885
|
+
event = SRecord.new(event_id: "df8b2ba3-4e2c-4888-8d14-4364855fa80e")
|
886
|
+
repository.append_to_stream(event, global_stream, version_any)
|
936
887
|
|
937
|
-
|
938
|
-
|
939
|
-
SRecord.new,
|
940
|
-
], stream, version_none)
|
888
|
+
expect(read_events_forward(repository, count: 10)).to eq([event])
|
889
|
+
end
|
941
890
|
|
942
|
-
|
891
|
+
specify "events not persisted if append failed" do
|
943
892
|
repository.append_to_stream([
|
944
|
-
SRecord.new
|
945
|
-
event_id: '9bedf448-e4d0-41a3-a8cd-f94aec7aa763'
|
946
|
-
),
|
893
|
+
SRecord.new,
|
947
894
|
], stream, version_none)
|
948
|
-
end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
|
949
|
-
expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
|
950
|
-
end
|
951
895
|
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
896
|
+
expect do
|
897
|
+
repository.append_to_stream([
|
898
|
+
SRecord.new(
|
899
|
+
event_id: '9bedf448-e4d0-41a3-a8cd-f94aec7aa763'
|
900
|
+
),
|
901
|
+
], stream, version_none)
|
902
|
+
end.to raise_error(WrongExpectedEventVersion)
|
903
|
+
expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
|
904
|
+
end
|
957
905
|
|
958
|
-
|
959
|
-
|
906
|
+
specify 'linking non-existent event' do
|
907
|
+
expect do
|
908
|
+
repository.link_to_stream('72922e65-1b32-4e97-8023-03ae81dd3a27', stream_flow, version_none)
|
909
|
+
end.to raise_error do |err|
|
910
|
+
expect(err).to be_a(EventNotFound)
|
911
|
+
expect(err.event_id).to eq('72922e65-1b32-4e97-8023-03ae81dd3a27')
|
912
|
+
expect(err.message).to eq('Event not found: 72922e65-1b32-4e97-8023-03ae81dd3a27')
|
913
|
+
end
|
914
|
+
end
|
960
915
|
|
961
|
-
|
962
|
-
|
963
|
-
repository.read_event('72922e65-1b32-4e97-8023-03ae81dd3a27')
|
964
|
-
end.to raise_error do |err|
|
965
|
-
expect(err).to be_a(RubyEventStore::EventNotFound)
|
966
|
-
expect(err.event_id).to eq('72922e65-1b32-4e97-8023-03ae81dd3a27')
|
967
|
-
expect(err.message).to eq('Event not found: 72922e65-1b32-4e97-8023-03ae81dd3a27')
|
916
|
+
specify 'read returns enumerator' do
|
917
|
+
expect(repository.read(specification.result)).to be_kind_of(Enumerator)
|
968
918
|
end
|
969
|
-
end
|
970
919
|
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
expect(
|
977
|
-
|
978
|
-
|
920
|
+
specify 'can store arbitrary binary data' do
|
921
|
+
skip unless test_binary
|
922
|
+
binary = "\xB0"
|
923
|
+
expect(binary.valid_encoding?).to eq(false)
|
924
|
+
binary.force_encoding("binary")
|
925
|
+
expect(binary.valid_encoding?).to eq(true)
|
926
|
+
|
927
|
+
repository.append_to_stream(
|
928
|
+
event = SRecord.new(data: binary, metadata: binary),
|
929
|
+
stream,
|
930
|
+
version_none
|
931
|
+
)
|
979
932
|
end
|
980
|
-
end
|
981
933
|
|
982
|
-
|
983
|
-
|
984
|
-
|
934
|
+
specify do
|
935
|
+
expect(repository.read(specification.in_batches.result)).to be_kind_of(Enumerator)
|
936
|
+
events = Array.new(10) { SRecord.new }
|
937
|
+
repository.append_to_stream(
|
938
|
+
events,
|
939
|
+
Stream.new("Dummy"),
|
940
|
+
ExpectedVersion.none
|
941
|
+
)
|
942
|
+
expect(repository.read(specification.in_batches.result)).to be_kind_of(Enumerator)
|
943
|
+
end
|
985
944
|
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
)
|
999
|
-
end
|
945
|
+
specify do
|
946
|
+
events = Array.new(400) { SRecord.new }
|
947
|
+
repository.append_to_stream(
|
948
|
+
events[200...400],
|
949
|
+
Stream.new("Foo"),
|
950
|
+
ExpectedVersion.none
|
951
|
+
)
|
952
|
+
repository.append_to_stream(
|
953
|
+
events[0...200],
|
954
|
+
Stream.new("Dummy"),
|
955
|
+
ExpectedVersion.none
|
956
|
+
)
|
1000
957
|
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
events[
|
1005
|
-
|
1006
|
-
RubyEventStore::ExpectedVersion.none
|
1007
|
-
)
|
1008
|
-
repository.append_to_stream(
|
1009
|
-
events[0...200],
|
1010
|
-
RubyEventStore::Stream.new("Dummy"),
|
1011
|
-
RubyEventStore::ExpectedVersion.none
|
1012
|
-
)
|
958
|
+
batches = repository.read(specification.stream("Dummy").in_batches.result).to_a
|
959
|
+
expect(batches.size).to eq(2)
|
960
|
+
expect(batches[0].size).to eq(100)
|
961
|
+
expect(batches[0]).to eq(events[0..99])
|
962
|
+
end
|
1013
963
|
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
964
|
+
specify do
|
965
|
+
events = Array.new(200) { SRecord.new }
|
966
|
+
repository.append_to_stream(
|
967
|
+
events,
|
968
|
+
Stream.new(GLOBAL_STREAM),
|
969
|
+
ExpectedVersion.any
|
970
|
+
)
|
1019
971
|
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
events
|
1024
|
-
|
1025
|
-
RubyEventStore::ExpectedVersion.any
|
1026
|
-
)
|
972
|
+
batches = repository.read(specification.in_batches.result).to_a
|
973
|
+
expect(batches.size).to eq(2)
|
974
|
+
expect(batches[0].size).to eq(100)
|
975
|
+
expect(batches[0]).to eq(events[0..99])
|
976
|
+
end
|
1027
977
|
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
978
|
+
specify do
|
979
|
+
events = Array.new(200) { SRecord.new }
|
980
|
+
repository.append_to_stream(
|
981
|
+
events,
|
982
|
+
Stream.new(GLOBAL_STREAM),
|
983
|
+
ExpectedVersion.any
|
984
|
+
)
|
1033
985
|
|
1034
|
-
|
1035
|
-
|
1036
|
-
repository.append_to_stream(
|
1037
|
-
events,
|
1038
|
-
RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
|
1039
|
-
RubyEventStore::ExpectedVersion.any
|
1040
|
-
)
|
986
|
+
expect(repository.read(specification.in_batches(200).result).to_a.size).to eq(1)
|
987
|
+
end
|
1041
988
|
|
1042
|
-
|
1043
|
-
|
989
|
+
specify do
|
990
|
+
events = Array.new(200) { SRecord.new }
|
991
|
+
repository.append_to_stream(
|
992
|
+
events,
|
993
|
+
Stream.new(GLOBAL_STREAM),
|
994
|
+
ExpectedVersion.any
|
995
|
+
)
|
1044
996
|
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
events
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
997
|
+
batches = repository.read(specification.limit(199).in_batches.result).to_a
|
998
|
+
expect(batches.size).to eq(2)
|
999
|
+
expect(batches[0].size).to eq(100)
|
1000
|
+
expect(batches[0]).to eq(events[0..99])
|
1001
|
+
expect(batches[1].size).to eq(99)
|
1002
|
+
expect(batches[1]).to eq(events[100..198])
|
1003
|
+
end
|
1052
1004
|
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1005
|
+
specify do
|
1006
|
+
events = Array.new(200) { SRecord.new }
|
1007
|
+
repository.append_to_stream(
|
1008
|
+
events,
|
1009
|
+
Stream.new(GLOBAL_STREAM),
|
1010
|
+
ExpectedVersion.any
|
1011
|
+
)
|
1060
1012
|
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
events
|
1065
|
-
|
1066
|
-
RubyEventStore::ExpectedVersion.any
|
1067
|
-
)
|
1013
|
+
batches = repository.read(specification.limit(99).in_batches.result).to_a
|
1014
|
+
expect(batches.size).to eq(1)
|
1015
|
+
expect(batches[0].size).to eq(99)
|
1016
|
+
expect(batches[0]).to eq(events[0..98])
|
1017
|
+
end
|
1068
1018
|
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1019
|
+
specify do
|
1020
|
+
events = Array.new(200) { SRecord.new }
|
1021
|
+
repository.append_to_stream(
|
1022
|
+
events,
|
1023
|
+
Stream.new(GLOBAL_STREAM),
|
1024
|
+
ExpectedVersion.any
|
1025
|
+
)
|
1074
1026
|
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
events
|
1079
|
-
|
1080
|
-
RubyEventStore::ExpectedVersion.any
|
1081
|
-
)
|
1027
|
+
batches = repository.read(specification.backward.limit(99).in_batches.result).to_a
|
1028
|
+
expect(batches.size).to eq(1)
|
1029
|
+
expect(batches[0].size).to eq(99)
|
1030
|
+
expect(batches[0]).to eq(events[101..-1].reverse)
|
1031
|
+
end
|
1082
1032
|
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1033
|
+
specify do
|
1034
|
+
events = Array.new(200) { SRecord.new }
|
1035
|
+
repository.append_to_stream(
|
1036
|
+
events,
|
1037
|
+
Stream.new(GLOBAL_STREAM),
|
1038
|
+
ExpectedVersion.any
|
1039
|
+
)
|
1088
1040
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
events
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1041
|
+
batches = repository.read(specification.from(events[100].event_id).limit(99).in_batches.result).to_a
|
1042
|
+
expect(batches.size).to eq(1)
|
1043
|
+
expect(batches[0].size).to eq(99)
|
1044
|
+
expect(batches[0]).to eq(events[101..199])
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
specify do
|
1048
|
+
expect(repository.read(specification.read_first.result)).to be_nil
|
1049
|
+
expect(repository.read(specification.read_last.result)).to be_nil
|
1050
|
+
|
1051
|
+
events = Array.new(5) { SRecord.new }
|
1052
|
+
repository.append_to_stream(
|
1053
|
+
events,
|
1054
|
+
Stream.new(GLOBAL_STREAM),
|
1055
|
+
ExpectedVersion.any
|
1056
|
+
)
|
1057
|
+
|
1058
|
+
expect(repository.read(specification.stream("Any").read_first.result)).to be_nil
|
1059
|
+
expect(repository.read(specification.stream("Any").read_last.result)).to be_nil
|
1060
|
+
|
1061
|
+
expect(repository.read(specification.read_first.result)).to eq(events[0])
|
1062
|
+
expect(repository.read(specification.read_last.result)).to eq(events[4])
|
1063
|
+
|
1064
|
+
expect(repository.read(specification.backward.read_first.result)).to eq(events[4])
|
1065
|
+
expect(repository.read(specification.backward.read_last.result)).to eq(events[0])
|
1066
|
+
|
1067
|
+
expect(repository.read(specification.from(events[2].event_id).read_first.result)).to eq(events[3])
|
1068
|
+
expect(repository.read(specification.from(events[2].event_id).read_last.result)).to eq(events[4])
|
1069
|
+
|
1070
|
+
expect(repository.read(specification.from(events[2].event_id).backward.read_first.result)).to eq(events[1])
|
1071
|
+
expect(repository.read(specification.from(events[2].event_id).backward.read_last.result)).to eq(events[0])
|
1072
|
+
|
1073
|
+
expect(repository.read(specification.from(events[4].event_id).read_first.result)).to be_nil
|
1074
|
+
expect(repository.read(specification.from(events[4].event_id).read_last.result)).to be_nil
|
1075
|
+
|
1076
|
+
expect(repository.read(specification.from(events[0].event_id).backward.read_first.result)).to be_nil
|
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])
|
1096
1081
|
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
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
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
context "#update_messages" do
|
1093
|
+
specify "changes events" do
|
1094
|
+
skip unless test_change
|
1095
|
+
events = Array.new(5) { SRecord.new }
|
1096
|
+
repository.append_to_stream(
|
1097
|
+
events[0..2],
|
1098
|
+
Stream.new("whatever"),
|
1099
|
+
ExpectedVersion.any
|
1100
|
+
)
|
1101
|
+
repository.append_to_stream(
|
1102
|
+
events[3..4],
|
1103
|
+
Stream.new("elo"),
|
1104
|
+
ExpectedVersion.any
|
1105
|
+
)
|
1106
|
+
repository.update_messages([
|
1107
|
+
a = SRecord.new(event_id: events[0].event_id.clone, data: events[0].data, metadata: events[0].metadata, event_type: events[0].event_type),
|
1108
|
+
b = SRecord.new(event_id: events[1].event_id.dup, data: '{"test":1}', metadata: events[1].metadata, event_type: events[1].event_type),
|
1109
|
+
c = SRecord.new(event_id: events[2].event_id, data: events[2].data, metadata: '{"test":2}', event_type: events[2].event_type),
|
1110
|
+
d = SRecord.new(event_id: events[3].event_id.clone, data: events[3].data, metadata: events[3].metadata, event_type: "event_type3"),
|
1111
|
+
e = SRecord.new(event_id: events[4].event_id.dup, data: '{"test":4}', metadata: '{"test":42}', event_type: "event_type4"),
|
1112
|
+
])
|
1113
|
+
expect(repository.read(specification.result).to_a).to eq([a,b,c,d,e])
|
1114
|
+
expect(repository.read(specification.stream("whatever").result).to_a).to eq([a,b,c])
|
1115
|
+
expect(repository.read(specification.stream("elo").result).to_a).to eq([d,e])
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
specify "cannot change unexisting event" do
|
1119
|
+
skip unless test_change
|
1120
|
+
e = SRecord.new
|
1121
|
+
expect{ repository.update_messages([e]) }.to raise_error do |err|
|
1122
|
+
expect(err).to be_a(EventNotFound)
|
1123
|
+
expect(err.event_id).to eq(e.event_id)
|
1124
|
+
expect(err.message).to eq("Event not found: #{e.event_id}")
|
1125
|
+
end
|
1126
|
+
end
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
specify do
|
1130
|
+
event_1 = SRecord.new(event_id: '8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea')
|
1131
|
+
event_2 = SRecord.new(event_id: '8cee1139-4f96-483a-a175-2b947283c3c7')
|
1132
|
+
event_3 = SRecord.new(event_id: 'd345f86d-b903-4d78-803f-38990c078d9e')
|
1133
|
+
stream_a = Stream.new('Stream A')
|
1134
|
+
stream_b = Stream.new('Stream B')
|
1135
|
+
stream_c = Stream.new('Stream C')
|
1136
|
+
repository.append_to_stream([event_1, event_2], stream_a, version_any)
|
1137
|
+
repository.append_to_stream([event_3], stream_b, version_any)
|
1138
|
+
repository.link_to_stream(event_1.event_id, stream_c, version_none)
|
1139
|
+
|
1140
|
+
expect(repository.streams_of('8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea')).to eq [stream_a, stream_c]
|
1141
|
+
expect(repository.streams_of('8cee1139-4f96-483a-a175-2b947283c3c7')).to eq [stream_a]
|
1142
|
+
expect(repository.streams_of('d345f86d-b903-4d78-803f-38990c078d9e')).to eq [stream_b]
|
1143
|
+
expect(repository.streams_of('d10c8fe9-2163-418d-ba47-88c9a1f9391b')).to eq []
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
specify do
|
1147
|
+
e1 = SRecord.new(event_id: '8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea')
|
1148
|
+
e2 = SRecord.new(event_id: '8cee1139-4f96-483a-a175-2b947283c3c7')
|
1149
|
+
e3 = SRecord.new(event_id: 'd345f86d-b903-4d78-803f-38990c078d9e')
|
1150
|
+
stream = Stream.new('Stream A')
|
1151
|
+
repository.append_to_stream([e1, e2, e3], stream, version_any)
|
1152
|
+
|
1153
|
+
expect(repository.read(specification.with_id([
|
1154
|
+
'8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea'
|
1155
|
+
]).read_first.result)).to eq(e1)
|
1156
|
+
expect(repository.read(specification.with_id([
|
1157
|
+
'd345f86d-b903-4d78-803f-38990c078d9e'
|
1158
|
+
]).read_first.result)).to eq(e3)
|
1159
|
+
expect(repository.read(specification.with_id([
|
1160
|
+
'c31b327c-0da1-4178-a3cd-d2f6bb5d0688'
|
1161
|
+
]).read_first.result)).to eq(nil)
|
1162
|
+
expect(repository.read(specification.with_id([
|
1163
|
+
'8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea',
|
1164
|
+
'd345f86d-b903-4d78-803f-38990c078d9e'
|
1165
|
+
]).in_batches.result).to_a[0]).to eq([e1,e3])
|
1166
|
+
expect(repository.read(specification.stream('Stream A').with_id([
|
1167
|
+
'8cee1139-4f96-483a-a175-2b947283c3c7'
|
1168
|
+
]).read_first.result)).to eq(e2)
|
1169
|
+
expect(repository.read(specification.stream('Stream B').with_id([
|
1170
|
+
'8cee1139-4f96-483a-a175-2b947283c3c7'
|
1171
|
+
]).read_first.result)).to eq(nil)
|
1172
|
+
expect(repository.read(specification.stream('Stream B').with_id([
|
1173
|
+
'c31b327c-0da1-4178-a3cd-d2f6bb5d0688'
|
1174
|
+
]).read_first.result)).to eq(nil)
|
1175
|
+
expect(repository.read(specification.with_id([]).result).to_a).to eq([])
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
specify do
|
1179
|
+
e1 = SRecord.new(event_type: Type1.to_s)
|
1180
|
+
e2 = SRecord.new(event_type: Type2.to_s)
|
1181
|
+
e3 = SRecord.new(event_type: Type1.to_s)
|
1182
|
+
stream = Stream.new('Stream A')
|
1183
|
+
repository.append_to_stream([e1, e2, e3], stream, version_any)
|
1184
|
+
|
1185
|
+
expect(repository.read(specification.of_type([Type1]).result).to_a).to eq([e1,e3])
|
1186
|
+
expect(repository.read(specification.of_type([Type2]).result).to_a).to eq([e2])
|
1187
|
+
expect(repository.read(specification.of_type([Type3]).result).to_a).to eq([])
|
1188
|
+
expect(repository.read(specification.of_type([Type1, Type2, Type3]).result).to_a).to eq([e1,e2,e3])
|
1189
|
+
end
|
1190
|
+
|
1191
|
+
specify do
|
1192
|
+
stream = Stream.new('Stream A')
|
1193
|
+
dummy = Stream.new('Dummy')
|
1194
|
+
|
1195
|
+
expect(repository.count(specification.result)).to eq(0)
|
1196
|
+
(1..3).each do
|
1197
|
+
repository.append_to_stream([SRecord.new(event_type: Type1.to_s)], stream, version_any)
|
1198
|
+
end
|
1199
|
+
expect(repository.count(specification.result)).to eq(3)
|
1200
|
+
event_id = SecureRandom.uuid
|
1201
|
+
repository.append_to_stream([SRecord.new(event_type: Type1.to_s, event_id: event_id)], dummy, version_any)
|
1202
|
+
expect(repository.count(specification.result)).to eq(4)
|
1203
|
+
expect(repository.count(specification.in_batches.result)).to eq(4)
|
1204
|
+
expect(repository.count(specification.in_batches(2).result)).to eq(4)
|
1205
|
+
|
1206
|
+
expect(repository.count(specification.with_id([event_id]).result)).to eq(1)
|
1207
|
+
not_existing_uuid = SecureRandom.uuid
|
1208
|
+
expect(repository.count(specification.with_id([not_existing_uuid]).result)).to eq(0)
|
1209
|
+
|
1210
|
+
expect(repository.count(specification.stream(stream.name).result)).to eq(3)
|
1211
|
+
expect(repository.count(specification.stream('Dummy').result)).to eq(1)
|
1212
|
+
expect(repository.count(specification.stream('not-existing-stream').result)).to eq(0)
|
1213
|
+
|
1214
|
+
repository.append_to_stream([SRecord.new(event_type: Type1.to_s)], dummy, version_any)
|
1215
|
+
expect(repository.count(specification.from(event_id).result)).to eq(1)
|
1216
|
+
expect(repository.count(specification.stream("Dummy").from(event_id).result)).to eq(1)
|
1217
|
+
expect(repository.count(specification.stream("Dummy").to(event_id).result)).to eq(0)
|
1218
|
+
|
1219
|
+
expect(repository.count(specification.limit(100).result)).to eq(5)
|
1220
|
+
expect(repository.count(specification.limit(2).result)).to eq(2)
|
1221
|
+
|
1222
|
+
repository.append_to_stream([SRecord.new(event_type: Type2.to_s)], dummy, version_any)
|
1223
|
+
repository.append_to_stream([SRecord.new(event_type: Type3.to_s)], dummy, version_any)
|
1224
|
+
repository.append_to_stream([SRecord.new(event_type: Type3.to_s)], dummy, version_any)
|
1225
|
+
expect(repository.count(specification.of_type([Type1]).result)).to eq(5)
|
1226
|
+
expect(repository.count(specification.of_type([Type2]).result)).to eq(1)
|
1227
|
+
expect(repository.count(specification.of_type([Type3]).result)).to eq(2)
|
1228
|
+
expect(repository.count(specification.stream("Dummy").of_type([Type3]).result)).to eq(2)
|
1229
|
+
expect(repository.count(specification.stream(stream.name).of_type([Type3]).result)).to eq(0)
|
1230
|
+
end
|
1101
1231
|
end
|
1102
1232
|
end
|