ruby_event_store 0.29.0 → 0.30.0

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.
@@ -58,6 +58,7 @@ module RubyEventStore
58
58
  end
59
59
 
60
60
  private
61
+
61
62
  def valid_starting_point?(start)
62
63
  return true if start === :head
63
64
  if streams.any?
@@ -67,44 +68,16 @@ module RubyEventStore
67
68
  end
68
69
  end
69
70
 
70
- def reduce_events(events, initial_state)
71
- events.reduce(initial_state, &method(:transition))
72
- end
73
-
74
- def read_events_from_stream(event_store, stream_name, start, count)
75
- event_store.read_events_forward(stream_name, start: start, count: count)
76
- end
77
-
78
71
  def reduce_from_streams(event_store, start, count)
79
72
  raise ArgumentError.new('Start must be an array with event ids or :head') unless valid_starting_point?(start)
80
73
  streams.zip(start_events(start)).reduce(initial_state) do |state, (stream_name, start_event_id)|
81
- reader = ->(from){ read_events_from_stream(event_store, stream_name, from, count) }
82
- read(state, start_event_id, reader)
74
+ event_store.read.in_batches(count).stream(stream_name).from(start_event_id).each.reduce(state, &method(:transition))
83
75
  end
84
76
  end
85
77
 
86
- def read_events_from_all_streams(event_store, start, count)
87
- event_store.read_all_streams_forward(start: start, count: count)
88
- end
89
-
90
78
  def reduce_from_all_streams(event_store, start, count)
91
79
  raise ArgumentError.new('Start must be valid event id or :head') unless valid_starting_point?(start)
92
- reader = ->(from){ read_events_from_all_streams(event_store, from, count) }
93
- read(initial_state, start, reader)
94
- end
95
-
96
- def read(initial_state, start, reader)
97
- state = initial_state
98
-
99
- loop do
100
- events = reader.call(start)
101
- break if events.empty?
102
-
103
- reduce_events(events, state)
104
- start = events.last.event_id
105
- end
106
-
107
- state
80
+ event_store.read.in_batches(count).from(start).each.reduce(initial_state, &method(:transition))
108
81
  end
109
82
 
110
83
  def start_events(start)
@@ -6,19 +6,32 @@ class SRecord
6
6
  event_type: SecureRandom.uuid
7
7
  )
8
8
  RubyEventStore::SerializedRecord.new(
9
- event_id: event_id,
10
- data: data,
11
- metadata: metadata,
9
+ event_id: event_id,
10
+ data: data,
11
+ metadata: metadata,
12
12
  event_type: event_type,
13
13
  )
14
14
  end
15
15
  end
16
16
 
17
17
  RSpec.shared_examples :event_repository do |repository_class|
18
- let(:repository) { subject || repository_class.new }
18
+ let(:repository) { subject || repository_class.new }
19
+ let(:mapper) { RubyEventStore::Mappers::NullMapper.new }
20
+ let(:specification) { RubyEventStore::Specification.new(repository, mapper) }
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) }
19
33
 
20
34
  def read_stream_events_forward(repository, stream)
21
- specification = RubyEventStore::Specification.new(repository)
22
35
  repository.read(
23
36
  specification
24
37
  .stream(stream.name)
@@ -27,7 +40,6 @@ RSpec.shared_examples :event_repository do |repository_class|
27
40
  end
28
41
 
29
42
  def read_stream_events_backward(repository, stream)
30
- specification = RubyEventStore::Specification.new(repository)
31
43
  repository.read(
32
44
  specification
33
45
  .stream(stream.name)
@@ -37,7 +49,6 @@ RSpec.shared_examples :event_repository do |repository_class|
37
49
  end
38
50
 
39
51
  def read_events_forward(repository, stream, start, count)
40
- specification = RubyEventStore::Specification.new(repository)
41
52
  repository.read(
42
53
  specification
43
54
  .stream(stream.name)
@@ -48,7 +59,6 @@ RSpec.shared_examples :event_repository do |repository_class|
48
59
  end
49
60
 
50
61
  def read_events_backward(repository, stream, start, count)
51
- specification = RubyEventStore::Specification.new(repository)
52
62
  repository.read(
53
63
  specification
54
64
  .stream(stream.name)
@@ -60,7 +70,6 @@ RSpec.shared_examples :event_repository do |repository_class|
60
70
  end
61
71
 
62
72
  def read_all_streams_forward(repository, start, count)
63
- specification = RubyEventStore::Specification.new(repository)
64
73
  repository.read(
65
74
  specification
66
75
  .from(start)
@@ -70,7 +79,6 @@ RSpec.shared_examples :event_repository do |repository_class|
70
79
  end
71
80
 
72
81
  def read_all_streams_backward(repository, start, count)
73
- specification = RubyEventStore::Specification.new(repository)
74
82
  repository.read(
75
83
  specification
76
84
  .from(start)
@@ -86,8 +94,8 @@ RSpec.shared_examples :event_repository do |repository_class|
86
94
 
87
95
  specify 'append_to_stream returns self' do
88
96
  repository.
89
- append_to_stream(event = SRecord.new, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none).
90
- append_to_stream(event = SRecord.new, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(0))
97
+ append_to_stream(event = SRecord.new, stream, version_none).
98
+ append_to_stream(event = SRecord.new, stream, version_0)
91
99
  end
92
100
 
93
101
  specify 'link_to_stream returns self' do
@@ -95,225 +103,225 @@ RSpec.shared_examples :event_repository do |repository_class|
95
103
  event0 = SRecord.new
96
104
  event1 = SRecord.new
97
105
  repository.
98
- append_to_stream([event0, event1], RubyEventStore::Stream.new("stream0"), RubyEventStore::ExpectedVersion.none).
99
- link_to_stream(event0.event_id, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none).
100
- link_to_stream(event1.event_id, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.new(0))
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)
101
109
  end
102
110
 
103
111
  specify 'adds an initial event to a new stream' do
104
- repository.append_to_stream(event = SRecord.new, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
112
+ repository.append_to_stream(event = SRecord.new, stream, version_none)
105
113
  expect(read_all_streams_forward(repository, :head, 1).first).to eq(event)
106
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream')).first).to eq(event)
107
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("other_stream"))).to be_empty
114
+ expect(read_stream_events_forward(repository, stream).first).to eq(event)
115
+ expect(read_stream_events_forward(repository, stream_other)).to be_empty
108
116
  end
109
117
 
110
118
  specify 'links an initial event to a new stream' do
111
119
  skip unless test_link_events_to_stream
112
120
  repository.
113
- append_to_stream(event = SRecord.new, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none).
114
- link_to_stream(event.event_id, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
121
+ append_to_stream(event = SRecord.new, stream, version_none).
122
+ link_to_stream(event.event_id, stream_flow, version_none)
115
123
 
116
124
  expect(read_all_streams_forward(repository, :head, 1).first).to eq(event)
117
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream')).first).to eq(event)
118
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([event])
119
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("other"))).to be_empty
125
+ expect(read_stream_events_forward(repository, stream).first).to eq(event)
126
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([event])
127
+ expect(read_stream_events_forward(repository, stream_other)).to be_empty
120
128
  end
121
129
 
122
130
  specify 'adds multiple initial events to a new stream' do
123
131
  repository.append_to_stream([
124
- event0 = SRecord.new(event_id: SecureRandom.uuid),
125
- event1 = SRecord.new(event_id: SecureRandom.uuid),
126
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
132
+ event0 = SRecord.new,
133
+ event1 = SRecord.new,
134
+ ], stream, version_none)
127
135
  expect(read_all_streams_forward(repository, :head, 2)).to eq([event0, event1])
128
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1])
136
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1])
129
137
  end
130
138
 
131
139
  specify 'links multiple initial events to a new stream' do
132
140
  skip unless test_link_events_to_stream
133
141
  repository.append_to_stream([
134
- event0 = SRecord.new(event_id: SecureRandom.uuid),
135
- event1 = SRecord.new(event_id: SecureRandom.uuid),
136
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none).link_to_stream([
142
+ event0 = SRecord.new,
143
+ event1 = SRecord.new,
144
+ ], stream, version_none).link_to_stream([
137
145
  event0.event_id,
138
146
  event1.event_id,
139
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
147
+ ], stream_flow, version_none)
140
148
  expect(read_all_streams_forward(repository, :head, 2)).to eq([event0, event1])
141
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([event0, event1])
149
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1])
142
150
  end
143
151
 
144
152
  specify 'correct expected version on second write' do
145
153
  repository.append_to_stream([
146
- event0 = SRecord.new(event_id: SecureRandom.uuid),
147
- event1 = SRecord.new(event_id: SecureRandom.uuid),
148
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
154
+ event0 = SRecord.new,
155
+ event1 = SRecord.new,
156
+ ], stream, version_none)
149
157
  repository.append_to_stream([
150
- event2 = SRecord.new(event_id: SecureRandom.uuid),
151
- event3 = SRecord.new(event_id: SecureRandom.uuid),
152
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(1))
158
+ event2 = SRecord.new,
159
+ event3 = SRecord.new,
160
+ ], stream, version_1)
153
161
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1, event2, event3])
154
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1, event2, event3])
162
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
155
163
  end
156
164
 
157
165
  specify 'correct expected version on second link' do
158
166
  skip unless test_link_events_to_stream
159
167
  repository.append_to_stream([
160
- event0 = SRecord.new(event_id: SecureRandom.uuid),
161
- event1 = SRecord.new(event_id: SecureRandom.uuid),
162
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none).append_to_stream([
163
- event2 = SRecord.new(event_id: SecureRandom.uuid),
164
- event3 = SRecord.new(event_id: SecureRandom.uuid),
165
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none).link_to_stream([
168
+ event0 = SRecord.new,
169
+ event1 = SRecord.new,
170
+ ], stream, version_none).append_to_stream([
171
+ event2 = SRecord.new,
172
+ event3 = SRecord.new,
173
+ ], stream_flow, version_none).link_to_stream([
166
174
  event0.event_id,
167
175
  event1.event_id,
168
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.new(1))
176
+ ], stream_flow, version_1)
169
177
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1, event2, event3])
170
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([event2, event3, event0, event1])
178
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([event2, event3, event0, event1])
171
179
  end
172
180
 
173
181
  specify 'incorrect expected version on second write' do
174
182
  repository.append_to_stream([
175
- event0 = SRecord.new(event_id: SecureRandom.uuid),
176
- event1 = SRecord.new(event_id: SecureRandom.uuid),
177
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
183
+ event0 = SRecord.new,
184
+ event1 = SRecord.new,
185
+ ], stream, version_none)
178
186
  expect do
179
187
  repository.append_to_stream([
180
- event2 = SRecord.new(event_id: SecureRandom.uuid),
181
- event3 = SRecord.new(event_id: SecureRandom.uuid),
182
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(0))
188
+ event2 = SRecord.new,
189
+ event3 = SRecord.new,
190
+ ], stream, version_0)
183
191
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
184
192
 
185
193
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1])
186
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1])
194
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1])
187
195
  end
188
196
 
189
197
  specify 'incorrect expected version on second link' do
190
198
  skip unless test_link_events_to_stream
191
199
  repository.append_to_stream([
192
- event0 = SRecord.new(event_id: SecureRandom.uuid),
193
- event1 = SRecord.new(event_id: SecureRandom.uuid),
194
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
200
+ event0 = SRecord.new,
201
+ event1 = SRecord.new,
202
+ ], stream, version_none)
195
203
  repository.append_to_stream([
196
- event2 = SRecord.new(event_id: SecureRandom.uuid),
197
- event3 = SRecord.new(event_id: SecureRandom.uuid),
198
- ], RubyEventStore::Stream.new("other"), RubyEventStore::ExpectedVersion.none)
204
+ event2 = SRecord.new,
205
+ event3 = SRecord.new,
206
+ ], stream_other, version_none)
199
207
  expect do
200
208
  repository.link_to_stream([
201
209
  event2.event_id,
202
210
  event3.event_id,
203
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(0))
211
+ ], stream, version_0)
204
212
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
205
213
 
206
214
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1, event2, event3])
207
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1])
215
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1])
208
216
  end
209
217
 
210
218
  specify ':none on first and subsequent write' do
211
219
  repository.append_to_stream([
212
- eventA = SRecord.new(event_id: SecureRandom.uuid),
213
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
220
+ eventA = SRecord.new,
221
+ ], stream, version_none)
214
222
  expect do
215
223
  repository.append_to_stream([
216
- eventB = SRecord.new(event_id: SecureRandom.uuid),
217
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
224
+ eventB = SRecord.new,
225
+ ], stream, version_none)
218
226
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
219
227
  expect(read_all_streams_forward(repository, :head, 1)).to eq([eventA])
220
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([eventA])
228
+ expect(read_stream_events_forward(repository, stream)).to eq([eventA])
221
229
  end
222
230
 
223
231
  specify ':none on first and subsequent link' do
224
232
  skip unless test_link_events_to_stream
225
233
  repository.append_to_stream([
226
- eventA = SRecord.new(event_id: SecureRandom.uuid),
227
- eventB = SRecord.new(event_id: SecureRandom.uuid),
228
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
234
+ eventA = SRecord.new,
235
+ eventB = SRecord.new,
236
+ ], stream, version_none)
229
237
 
230
- repository.link_to_stream([eventA.event_id], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
238
+ repository.link_to_stream([eventA.event_id], stream_flow, version_none)
231
239
  expect do
232
- repository.link_to_stream([eventB.event_id], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
240
+ repository.link_to_stream([eventB.event_id], stream_flow, version_none)
233
241
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
234
242
 
235
243
  expect(read_all_streams_forward(repository, :head, 1)).to eq([eventA])
236
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([eventA])
244
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([eventA])
237
245
  end
238
246
 
239
247
  specify ':any allows stream with best-effort order and no guarantee' do
240
248
  repository.append_to_stream([
241
- event0 = SRecord.new(event_id: SecureRandom.uuid),
242
- event1 = SRecord.new(event_id: SecureRandom.uuid),
243
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
249
+ event0 = SRecord.new,
250
+ event1 = SRecord.new,
251
+ ], stream, version_any)
244
252
  repository.append_to_stream([
245
- event2 = SRecord.new(event_id: SecureRandom.uuid),
246
- event3 = SRecord.new(event_id: SecureRandom.uuid),
247
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
253
+ event2 = SRecord.new,
254
+ event3 = SRecord.new,
255
+ ], stream, version_any)
248
256
  expect(read_all_streams_forward(repository, :head, 4).to_set).to eq(Set.new([event0, event1, event2, event3]))
249
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream')).to_set).to eq(Set.new([event0, event1, event2, event3]))
257
+ expect(read_stream_events_forward(repository, stream).to_set).to eq(Set.new([event0, event1, event2, event3]))
250
258
  end
251
259
 
252
260
  specify ':any allows linking in stream with best-effort order and no guarantee' do
253
261
  skip unless test_link_events_to_stream
254
262
  repository.append_to_stream([
255
- event0 = SRecord.new(event_id: SecureRandom.uuid),
256
- event1 = SRecord.new(event_id: SecureRandom.uuid),
257
- event2 = SRecord.new(event_id: SecureRandom.uuid),
258
- event3 = SRecord.new(event_id: SecureRandom.uuid),
259
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
263
+ event0 = SRecord.new,
264
+ event1 = SRecord.new,
265
+ event2 = SRecord.new,
266
+ event3 = SRecord.new,
267
+ ], stream, version_any)
260
268
 
261
269
  repository.link_to_stream([
262
270
  event0.event_id, event1.event_id,
263
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.any)
271
+ ], stream_flow, version_any)
264
272
  repository.link_to_stream([
265
273
  event2.event_id, event3.event_id,
266
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.any)
274
+ ], stream_flow, version_any)
267
275
 
268
276
  expect(read_all_streams_forward(repository, :head, 4).to_set).to eq(Set.new([event0, event1, event2, event3]))
269
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow")).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]))
270
278
  end
271
279
 
272
280
  specify ':auto queries for last position in given stream' do
273
281
  skip unless test_expected_version_auto
274
282
  repository.append_to_stream([
275
- eventA = SRecord.new(event_id: SecureRandom.uuid),
276
- eventB = SRecord.new(event_id: SecureRandom.uuid),
277
- eventC = SRecord.new(event_id: SecureRandom.uuid),
278
- ], RubyEventStore::Stream.new("another"), RubyEventStore::ExpectedVersion.auto)
283
+ eventA = SRecord.new,
284
+ eventB = SRecord.new,
285
+ eventC = SRecord.new,
286
+ ], stream_other, version_auto)
279
287
  repository.append_to_stream([
280
- event0 = SRecord.new(event_id: SecureRandom.uuid),
281
- event1 = SRecord.new(event_id: SecureRandom.uuid),
282
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
288
+ event0 = SRecord.new,
289
+ event1 = SRecord.new,
290
+ ], stream, version_auto)
283
291
  repository.append_to_stream([
284
- event2 = SRecord.new(event_id: SecureRandom.uuid),
285
- event3 = SRecord.new(event_id: SecureRandom.uuid),
286
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(1))
292
+ event2 = SRecord.new,
293
+ event3 = SRecord.new,
294
+ ], stream, version_1)
287
295
  end
288
296
 
289
297
  specify ':auto queries for last position in given stream when linking' do
290
298
  skip unless test_expected_version_auto
291
299
  skip unless test_link_events_to_stream
292
300
  repository.append_to_stream([
293
- eventA = SRecord.new(event_id: SecureRandom.uuid),
294
- eventB = SRecord.new(event_id: SecureRandom.uuid),
295
- eventC = SRecord.new(event_id: SecureRandom.uuid),
296
- ], RubyEventStore::Stream.new("another"), RubyEventStore::ExpectedVersion.auto)
301
+ eventA = SRecord.new,
302
+ eventB = SRecord.new,
303
+ eventC = SRecord.new,
304
+ ], stream_other, version_auto)
297
305
  repository.append_to_stream([
298
- event0 = SRecord.new(event_id: SecureRandom.uuid),
299
- event1 = SRecord.new(event_id: SecureRandom.uuid),
300
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
306
+ event0 = SRecord.new,
307
+ event1 = SRecord.new,
308
+ ], stream, version_auto)
301
309
  repository.link_to_stream([
302
310
  eventA.event_id,
303
311
  eventB.event_id,
304
312
  eventC.event_id,
305
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(1))
313
+ ], stream, version_1)
306
314
  end
307
315
 
308
316
  specify ':auto starts from 0' do
309
317
  skip unless test_expected_version_auto
310
318
  repository.append_to_stream([
311
- event0 = SRecord.new(event_id: SecureRandom.uuid),
312
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
319
+ event0 = SRecord.new,
320
+ ], stream, version_auto)
313
321
  expect do
314
322
  repository.append_to_stream([
315
- event1 = SRecord.new(event_id: SecureRandom.uuid),
316
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
323
+ event1 = SRecord.new,
324
+ ], stream, version_none)
317
325
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
318
326
  end
319
327
 
@@ -321,15 +329,15 @@ RSpec.shared_examples :event_repository do |repository_class|
321
329
  skip unless test_expected_version_auto
322
330
  skip unless test_link_events_to_stream
323
331
  repository.append_to_stream([
324
- event0 = SRecord.new(event_id: SecureRandom.uuid),
325
- ], RubyEventStore::Stream.new("whatever"), RubyEventStore::ExpectedVersion.auto)
332
+ event0 = SRecord.new,
333
+ ], stream_other, version_auto)
326
334
  repository.link_to_stream([
327
335
  event0.event_id,
328
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
336
+ ], stream, version_auto)
329
337
  expect do
330
338
  repository.append_to_stream([
331
- event1 = SRecord.new(event_id: SecureRandom.uuid),
332
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
339
+ event1 = SRecord.new,
340
+ ], stream, version_none)
333
341
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
334
342
  end
335
343
 
@@ -338,102 +346,102 @@ RSpec.shared_examples :event_repository do |repository_class|
338
346
  # It is expected that there is higher level lock
339
347
  # So this query is safe from race conditions
340
348
  repository.append_to_stream([
341
- event0 = SRecord.new(event_id: SecureRandom.uuid),
342
- event1 = SRecord.new(event_id: SecureRandom.uuid),
343
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
349
+ event0 = SRecord.new,
350
+ event1 = SRecord.new,
351
+ ], stream, version_auto)
344
352
  repository.append_to_stream([
345
- event2 = SRecord.new(event_id: SecureRandom.uuid),
346
- event3 = SRecord.new(event_id: SecureRandom.uuid),
347
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
353
+ event2 = SRecord.new,
354
+ event3 = SRecord.new,
355
+ ], stream, version_auto)
348
356
  expect(read_all_streams_forward(repository, :head, 4)).to eq([
349
357
  event0, event1,
350
358
  event2, event3
351
359
  ])
352
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1, event2, event3])
360
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
353
361
  end
354
362
 
355
363
  specify ':auto queries for last position and follows in incremental way when linking' do
356
364
  skip unless test_expected_version_auto
357
365
  skip unless test_link_events_to_stream
358
366
  repository.append_to_stream([
359
- event0 = SRecord.new(event_id: SecureRandom.uuid),
360
- event1 = SRecord.new(event_id: SecureRandom.uuid),
361
- event2 = SRecord.new(event_id: SecureRandom.uuid),
362
- event3 = SRecord.new(event_id: SecureRandom.uuid),
363
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
367
+ event0 = SRecord.new,
368
+ event1 = SRecord.new,
369
+ event2 = SRecord.new,
370
+ event3 = SRecord.new,
371
+ ], stream, version_auto)
364
372
  repository.link_to_stream([
365
373
  event0.event_id, event1.event_id,
366
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.auto)
374
+ ], stream_flow, version_auto)
367
375
  repository.link_to_stream([
368
376
  event2.event_id, event3.event_id,
369
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.auto)
377
+ ], stream_flow, version_auto)
370
378
  expect(read_all_streams_forward(repository, :head, 4)).to eq([
371
379
  event0, event1,
372
380
  event2, event3
373
381
  ])
374
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([event0, event1, event2, event3])
382
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1, event2, event3])
375
383
  end
376
384
 
377
385
  specify ':auto is compatible with manual expectation' do
378
386
  skip unless test_expected_version_auto
379
387
  repository.append_to_stream([
380
- event0 = SRecord.new(event_id: SecureRandom.uuid),
381
- event1 = SRecord.new(event_id: SecureRandom.uuid),
382
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
388
+ event0 = SRecord.new,
389
+ event1 = SRecord.new,
390
+ ], stream, version_auto)
383
391
  repository.append_to_stream([
384
- event2 = SRecord.new(event_id: SecureRandom.uuid),
385
- event3 = SRecord.new(event_id: SecureRandom.uuid),
386
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(1))
392
+ event2 = SRecord.new,
393
+ event3 = SRecord.new,
394
+ ], stream, version_1)
387
395
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1, event2, event3])
388
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1, event2, event3])
396
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
389
397
  end
390
398
 
391
399
  specify ':auto is compatible with manual expectation when linking' do
392
400
  skip unless test_expected_version_auto
393
401
  skip unless test_link_events_to_stream
394
402
  repository.append_to_stream([
395
- event0 = SRecord.new(event_id: SecureRandom.uuid),
396
- event1 = SRecord.new(event_id: SecureRandom.uuid),
397
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
403
+ event0 = SRecord.new,
404
+ event1 = SRecord.new,
405
+ ], stream, version_auto)
398
406
  repository.link_to_stream([
399
407
  event0.event_id,
400
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.auto)
408
+ ], stream_flow, version_auto)
401
409
  repository.link_to_stream([
402
410
  event1.event_id,
403
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.new(0))
411
+ ], stream_flow, version_0)
404
412
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1,])
405
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([event0, event1,])
413
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1,])
406
414
  end
407
415
 
408
416
  specify 'manual is compatible with auto expectation' do
409
417
  skip unless test_expected_version_auto
410
418
  repository.append_to_stream([
411
- event0 = SRecord.new(event_id: SecureRandom.uuid),
412
- event1 = SRecord.new(event_id: SecureRandom.uuid),
413
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
419
+ event0 = SRecord.new,
420
+ event1 = SRecord.new,
421
+ ], stream, version_none)
414
422
  repository.append_to_stream([
415
- event2 = SRecord.new(event_id: SecureRandom.uuid),
416
- event3 = SRecord.new(event_id: SecureRandom.uuid),
417
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
423
+ event2 = SRecord.new,
424
+ event3 = SRecord.new,
425
+ ], stream, version_auto)
418
426
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1, event2, event3])
419
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to eq([event0, event1, event2, event3])
427
+ expect(read_stream_events_forward(repository, stream)).to eq([event0, event1, event2, event3])
420
428
  end
421
429
 
422
430
  specify 'manual is compatible with auto expectation when linking' do
423
431
  skip unless test_expected_version_auto
424
432
  skip unless test_link_events_to_stream
425
433
  repository.append_to_stream([
426
- event0 = SRecord.new(event_id: SecureRandom.uuid),
427
- event1 = SRecord.new(event_id: SecureRandom.uuid),
428
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
434
+ event0 = SRecord.new,
435
+ event1 = SRecord.new,
436
+ ], stream, version_auto)
429
437
  repository.link_to_stream([
430
438
  event0.event_id,
431
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
439
+ ], stream_flow, version_none)
432
440
  repository.link_to_stream([
433
441
  event1.event_id,
434
- ], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.auto)
442
+ ], stream_flow, version_auto)
435
443
  expect(read_all_streams_forward(repository, :head, 4)).to eq([event0, event1])
436
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to eq([event0, event1])
444
+ expect(read_stream_events_forward(repository, stream_flow)).to eq([event0, event1])
437
445
  end
438
446
 
439
447
  specify 'unlimited concurrency for :any - everything should succeed', timeout: 10, mutant: false do
@@ -453,7 +461,7 @@ RSpec.shared_examples :event_repository do |repository_class|
453
461
  eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
454
462
  repository.append_to_stream([
455
463
  SRecord.new(event_id: eid),
456
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
464
+ ], stream, version_any)
457
465
  end
458
466
  rescue RubyEventStore::WrongExpectedEventVersion
459
467
  fail_occurred = true
@@ -463,8 +471,8 @@ RSpec.shared_examples :event_repository do |repository_class|
463
471
  wait_for_it = false
464
472
  threads.each(&:join)
465
473
  expect(fail_occurred).to eq(false)
466
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream')).size).to eq(400)
467
- events_in_stream = read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))
474
+ expect(read_stream_events_forward(repository, stream).size).to eq(400)
475
+ events_in_stream = read_stream_events_forward(repository, stream)
468
476
  expect(events_in_stream.size).to eq(400)
469
477
  events0 = events_in_stream.select do |ev|
470
478
  ev.event_id.start_with?("0-")
@@ -490,7 +498,7 @@ RSpec.shared_examples :event_repository do |repository_class|
490
498
  eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
491
499
  repository.append_to_stream([
492
500
  SRecord.new(event_id: eid),
493
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
501
+ ], stream, version_any)
494
502
  end
495
503
  end
496
504
 
@@ -500,7 +508,7 @@ RSpec.shared_examples :event_repository do |repository_class|
500
508
  begin
501
509
  100.times do |j|
502
510
  eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
503
- repository.link_to_stream(eid, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.any)
511
+ repository.link_to_stream(eid, stream_flow, version_any)
504
512
  end
505
513
  rescue RubyEventStore::WrongExpectedEventVersion
506
514
  fail_occurred = true
@@ -510,8 +518,8 @@ RSpec.shared_examples :event_repository do |repository_class|
510
518
  wait_for_it = false
511
519
  threads.each(&:join)
512
520
  expect(fail_occurred).to eq(false)
513
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow")).size).to eq(400)
514
- events_in_stream = read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))
521
+ expect(read_stream_events_forward(repository, stream_flow).size).to eq(400)
522
+ events_in_stream = read_stream_events_forward(repository, stream_flow)
515
523
  expect(events_in_stream.size).to eq(400)
516
524
  events0 = events_in_stream.select do |ev|
517
525
  ev.event_id.start_with?("0-")
@@ -540,7 +548,7 @@ RSpec.shared_examples :event_repository do |repository_class|
540
548
  eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
541
549
  repository.append_to_stream([
542
550
  SRecord.new(event_id: eid),
543
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
551
+ ], stream, version_auto)
544
552
  sleep(rand(concurrency_level) / 1000.0)
545
553
  rescue RubyEventStore::WrongExpectedEventVersion
546
554
  fail_occurred +=1
@@ -551,7 +559,7 @@ RSpec.shared_examples :event_repository do |repository_class|
551
559
  wait_for_it = false
552
560
  threads.each(&:join)
553
561
  expect(fail_occurred).to be > 0
554
- events_in_stream = read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))
562
+ events_in_stream = read_stream_events_forward(repository, stream)
555
563
  expect(events_in_stream.size).to be < 400
556
564
  expect(events_in_stream.size).to be >= 100
557
565
  events0 = events_in_stream.select do |ev|
@@ -578,7 +586,7 @@ RSpec.shared_examples :event_repository do |repository_class|
578
586
  eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
579
587
  repository.append_to_stream([
580
588
  SRecord.new(event_id: eid),
581
- ], RubyEventStore::Stream.new("whatever"), RubyEventStore::ExpectedVersion.any)
589
+ ], stream_other, version_any)
582
590
  end
583
591
  end
584
592
 
@@ -591,7 +599,7 @@ RSpec.shared_examples :event_repository do |repository_class|
591
599
  100.times do |j|
592
600
  begin
593
601
  eid = "0000000#{i}-#{sprintf("%04d", j)}-0000-0000-000000000000"
594
- repository.link_to_stream(eid, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.auto)
602
+ repository.link_to_stream(eid, stream, version_auto)
595
603
  sleep(rand(concurrency_level) / 1000.0)
596
604
  rescue RubyEventStore::WrongExpectedEventVersion
597
605
  fail_occurred +=1
@@ -602,7 +610,7 @@ RSpec.shared_examples :event_repository do |repository_class|
602
610
  wait_for_it = false
603
611
  threads.each(&:join)
604
612
  expect(fail_occurred).to be > 0
605
- events_in_stream = read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))
613
+ events_in_stream = read_stream_events_forward(repository, stream)
606
614
  expect(events_in_stream.size).to be < 400
607
615
  expect(events_in_stream.size).to be >= 100
608
616
  events0 = events_in_stream.select do |ev|
@@ -617,22 +625,22 @@ RSpec.shared_examples :event_repository do |repository_class|
617
625
 
618
626
  it 'appended event is stored in given stream' do
619
627
  expected_event = SRecord.new
620
- repository.append_to_stream(expected_event, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
628
+ repository.append_to_stream(expected_event, stream, version_any)
621
629
  expect(read_all_streams_forward(repository, :head, 1).first).to eq(expected_event)
622
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream')).first).to eq(expected_event)
623
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("other_stream"))).to be_empty
630
+ expect(read_stream_events_forward(repository, stream).first).to eq(expected_event)
631
+ expect(read_stream_events_forward(repository, stream_other)).to be_empty
624
632
  end
625
633
 
626
634
  it 'data attributes are retrieved' do
627
635
  event = SRecord.new(data: "{ order_id: 3 }")
628
- repository.append_to_stream(event, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
636
+ repository.append_to_stream(event, stream, version_any)
629
637
  retrieved_event = read_all_streams_forward(repository, :head, 1).first
630
638
  expect(retrieved_event.data).to eq("{ order_id: 3 }")
631
639
  end
632
640
 
633
641
  it 'metadata attributes are retrieved' do
634
642
  event = SRecord.new(metadata: "{ request_id: 3 }")
635
- repository.append_to_stream(event, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any)
643
+ repository.append_to_stream(event, stream, version_any)
636
644
  retrieved_event = read_all_streams_forward(repository, :head, 1).first
637
645
  expect(retrieved_event.metadata).to eq("{ request_id: 3 }")
638
646
  end
@@ -644,54 +652,54 @@ RSpec.shared_examples :event_repository do |repository_class|
644
652
  metadata: "{ request_id: 4 }",
645
653
  )
646
654
  repository.
647
- append_to_stream(event, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.any).
648
- link_to_stream(event.event_id, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.any)
649
- retrieved_event = read_stream_events_forward(repository, RubyEventStore::Stream.new("flow")).first
655
+ append_to_stream(event, stream, version_any).
656
+ link_to_stream(event.event_id, stream_flow, version_any)
657
+ retrieved_event = read_stream_events_forward(repository, stream_flow).first
650
658
  expect(retrieved_event.metadata).to eq("{ request_id: 4 }")
651
659
  expect(retrieved_event.data).to eq("{ order_id: 3 }")
652
660
  expect(event).to eq(retrieved_event)
653
661
  end
654
662
 
655
663
  it 'does not have deleted streams' do
656
- repository.append_to_stream(e1 = SRecord.new, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
657
- repository.append_to_stream(e2 = SRecord.new, RubyEventStore::Stream.new("other_stream"), RubyEventStore::ExpectedVersion.none)
664
+ repository.append_to_stream(e1 = SRecord.new, stream, version_none)
665
+ repository.append_to_stream(e2 = SRecord.new, stream_other, version_none)
658
666
 
659
- repository.delete_stream(RubyEventStore::Stream.new('stream'))
660
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new('stream'))).to be_empty
661
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("other_stream"))).to eq([e2])
667
+ repository.delete_stream(stream)
668
+ expect(read_stream_events_forward(repository, stream)).to be_empty
669
+ expect(read_stream_events_forward(repository, stream_other)).to eq([e2])
662
670
  expect(read_all_streams_forward(repository, :head, 10)).to eq([e1,e2])
663
671
  end
664
672
 
665
673
  it 'does not have deleted streams with linked events' do
666
674
  skip unless test_link_events_to_stream
667
675
  repository.
668
- append_to_stream(e1 = SRecord.new, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none).
669
- link_to_stream(e1.event_id, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
676
+ append_to_stream(e1 = SRecord.new, stream, version_none).
677
+ link_to_stream(e1.event_id, stream_flow, version_none)
670
678
 
671
- repository.delete_stream(RubyEventStore::Stream.new("flow"))
672
- expect(read_stream_events_forward(repository, RubyEventStore::Stream.new("flow"))).to be_empty
679
+ repository.delete_stream(stream_flow)
680
+ expect(read_stream_events_forward(repository, stream_flow)).to be_empty
673
681
  expect(read_all_streams_forward(repository, :head, 10)).to eq([e1])
674
682
  end
675
683
 
676
684
  it 'has or has not domain event' do
677
685
  just_an_id = 'd5c134c2-db65-4e87-b6ea-d196f8f1a292'
678
- repository.append_to_stream(SRecord.new(event_id: just_an_id), RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
686
+ repository.append_to_stream(SRecord.new(event_id: just_an_id), stream, version_none)
679
687
 
680
688
  expect(repository.has_event?(just_an_id)).to be_truthy
681
689
  expect(repository.has_event?(just_an_id.clone)).to be_truthy
682
690
  expect(repository.has_event?('any other id')).to be_falsey
683
691
 
684
- repository.delete_stream(RubyEventStore::Stream.new('stream'))
692
+ repository.delete_stream(stream)
685
693
  expect(repository.has_event?(just_an_id)).to be_truthy
686
694
  expect(repository.has_event?(just_an_id.clone)).to be_truthy
687
695
  end
688
696
 
689
697
  it 'knows last event in stream' do
690
- repository.append_to_stream(a =SRecord.new(event_id: '00000000-0000-0000-0000-000000000001'), RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
691
- repository.append_to_stream(b = SRecord.new(event_id: '00000000-0000-0000-0000-000000000002'), RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(0))
698
+ repository.append_to_stream(a =SRecord.new(event_id: '00000000-0000-0000-0000-000000000001'), stream, version_none)
699
+ repository.append_to_stream(b = SRecord.new(event_id: '00000000-0000-0000-0000-000000000002'), stream, version_0)
692
700
 
693
- expect(repository.last_stream_event(RubyEventStore::Stream.new('stream'))).to eq(b)
694
- expect(repository.last_stream_event(RubyEventStore::Stream.new("other_stream"))).to be_nil
701
+ expect(repository.last_stream_event(stream)).to eq(b)
702
+ expect(repository.last_stream_event(stream_other)).to be_nil
695
703
  end
696
704
 
697
705
  it 'knows last event in stream when linked' do
@@ -700,10 +708,10 @@ RSpec.shared_examples :event_repository do |repository_class|
700
708
  e0 = SRecord.new(event_id: '00000000-0000-0000-0000-000000000001'),
701
709
  e1 = SRecord.new(event_id: '00000000-0000-0000-0000-000000000002'),
702
710
  ],
703
- RubyEventStore::Stream.new('stream'),
704
- RubyEventStore::ExpectedVersion.none
705
- ).link_to_stream([e1.event_id, e0.event_id], RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
706
- expect(repository.last_stream_event(RubyEventStore::Stream.new("flow"))).to eq(e0)
711
+ stream,
712
+ version_none
713
+ ).link_to_stream([e1.event_id, e0.event_id], stream_flow, version_none)
714
+ expect(repository.last_stream_event(stream_flow)).to eq(e0)
707
715
  end
708
716
 
709
717
  it 'reads batch of events from stream forward & backward' do
@@ -719,21 +727,22 @@ RSpec.shared_examples :event_repository do |repository_class|
719
727
  ab60114c-011d-4d58-ab31-7ba65d99975e
720
728
  868cac42-3d19-4b39-84e8-cd32d65c2445
721
729
  ].map { |id| SRecord.new(event_id: id) }
722
- repository.append_to_stream(SRecord.new, RubyEventStore::Stream.new("other_stream"), RubyEventStore::ExpectedVersion.none)
730
+ repository.append_to_stream(SRecord.new, stream_other, version_none)
723
731
  events.each.with_index do |event, index|
724
- repository.append_to_stream(event, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(index - 1))
732
+ repository.append_to_stream(event, stream, RubyEventStore::ExpectedVersion.new(index - 1))
725
733
  end
726
- repository.append_to_stream(SRecord.new, RubyEventStore::Stream.new("other_stream"), RubyEventStore::ExpectedVersion.new(0))
727
-
728
- expect(read_events_forward(repository, RubyEventStore::Stream.new('stream'), :head, 3)).to eq(events.first(3))
729
- expect(read_events_forward(repository, RubyEventStore::Stream.new('stream'), :head, 100)).to eq(events)
730
- expect(read_events_forward(repository, RubyEventStore::Stream.new('stream'), events[4].event_id, 4)).to eq(events[5..8])
731
- expect(read_events_forward(repository, RubyEventStore::Stream.new('stream'), events[4].event_id, 100)).to eq(events[5..9])
732
-
733
- expect(read_events_backward(repository, RubyEventStore::Stream.new('stream'), :head, 3)).to eq(events.last(3).reverse)
734
- expect(read_events_backward(repository, RubyEventStore::Stream.new('stream'), :head, 100)).to eq(events.reverse)
735
- expect(read_events_backward(repository, RubyEventStore::Stream.new('stream'), events[4].event_id, 4)).to eq(events.first(4).reverse)
736
- expect(read_events_backward(repository, RubyEventStore::Stream.new('stream'), events[4].event_id, 100)).to eq(events.first(4).reverse)
734
+ repository.append_to_stream(SRecord.new, stream_other, version_0)
735
+
736
+ expect(read_events_forward(repository, stream, :head, 3)).to eq(events.first(3))
737
+ expect(read_events_forward(repository, stream, :head, 100)).to eq(events)
738
+ expect(repository.read(specification.stream(stream.name).from(events[4].event_id).result).to_a).to eq(events[5..9])
739
+ expect(read_events_forward(repository, stream, events[4].event_id, 4)).to eq(events[5..8])
740
+ expect(read_events_forward(repository, stream, events[4].event_id, 100)).to eq(events[5..9])
741
+
742
+ expect(read_events_backward(repository, stream, :head, 3)).to eq(events.last(3).reverse)
743
+ expect(read_events_backward(repository, stream, :head, 100)).to eq(events.reverse)
744
+ expect(read_events_backward(repository, stream, events[4].event_id, 4)).to eq(events.first(4).reverse)
745
+ expect(read_events_backward(repository, stream, events[4].event_id, 100)).to eq(events.first(4).reverse)
737
746
  end
738
747
 
739
748
  it 'reads batch of linked events from stream forward & backward' do
@@ -750,34 +759,34 @@ RSpec.shared_examples :event_repository do |repository_class|
750
759
  ab60114c-011d-4d58-ab31-7ba65d99975e
751
760
  868cac42-3d19-4b39-84e8-cd32d65c2445
752
761
  ].map { |id| SRecord.new(event_id: id) }
753
- repository.append_to_stream(SRecord.new, RubyEventStore::Stream.new("other_stream"), RubyEventStore::ExpectedVersion.none)
762
+ repository.append_to_stream(SRecord.new, stream_other, version_none)
754
763
  events.each.with_index do |event, index|
755
764
  repository.
756
- append_to_stream(event, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(index - 1)).
757
- link_to_stream(event.event_id, RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.new(index - 1))
765
+ append_to_stream(event, stream, RubyEventStore::ExpectedVersion.new(index - 1)).
766
+ link_to_stream(event.event_id, stream_flow, RubyEventStore::ExpectedVersion.new(index - 1))
758
767
  end
759
- repository.append_to_stream(SRecord.new, RubyEventStore::Stream.new("other_stream"), RubyEventStore::ExpectedVersion.new(0))
768
+ repository.append_to_stream(SRecord.new, stream_other, version_0)
760
769
 
761
- expect(read_events_forward(repository, RubyEventStore::Stream.new("flow"), :head, 3)).to eq(events.first(3))
762
- expect(read_events_forward(repository, RubyEventStore::Stream.new("flow"), :head, 100)).to eq(events)
763
- expect(read_events_forward(repository, RubyEventStore::Stream.new("flow"), events[4].event_id, 4)).to eq(events[5..8])
764
- expect(read_events_forward(repository, RubyEventStore::Stream.new("flow"), events[4].event_id, 100)).to eq(events[5..9])
770
+ expect(read_events_forward(repository, stream_flow, :head, 3)).to eq(events.first(3))
771
+ expect(read_events_forward(repository, stream_flow, :head, 100)).to eq(events)
772
+ expect(read_events_forward(repository, stream_flow, events[4].event_id, 4)).to eq(events[5..8])
773
+ expect(read_events_forward(repository, stream_flow, events[4].event_id, 100)).to eq(events[5..9])
765
774
 
766
- expect(read_events_backward(repository, RubyEventStore::Stream.new("flow"), :head, 3)).to eq(events.last(3).reverse)
767
- expect(read_events_backward(repository, RubyEventStore::Stream.new("flow"), :head, 100)).to eq(events.reverse)
768
- expect(read_events_backward(repository, RubyEventStore::Stream.new("flow"), events[4].event_id, 4)).to eq(events.first(4).reverse)
769
- expect(read_events_backward(repository, RubyEventStore::Stream.new("flow"), events[4].event_id, 100)).to eq(events.first(4).reverse)
775
+ expect(read_events_backward(repository, stream_flow, :head, 3)).to eq(events.last(3).reverse)
776
+ expect(read_events_backward(repository, stream_flow, :head, 100)).to eq(events.reverse)
777
+ expect(read_events_backward(repository, stream_flow, events[4].event_id, 4)).to eq(events.first(4).reverse)
778
+ expect(read_events_backward(repository, stream_flow, events[4].event_id, 100)).to eq(events.first(4).reverse)
770
779
  end
771
780
 
772
781
  it 'reads all stream events forward & backward' do
773
- s1 = RubyEventStore::Stream.new('stream')
774
- s2 = RubyEventStore::Stream.new("other_stream")
782
+ s1 = stream
783
+ s2 = stream_other
775
784
  repository.
776
- append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, RubyEventStore::ExpectedVersion.none).
777
- append_to_stream(b = SRecord.new(event_id: '34f88aca-aaba-4ca0-9256-8017b47528c5'), s2, RubyEventStore::ExpectedVersion.none).
778
- append_to_stream(c = SRecord.new(event_id: '8e61c864-ceae-4684-8726-97c34eb8fc4f'), s1, RubyEventStore::ExpectedVersion.new(0)).
779
- append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s2, RubyEventStore::ExpectedVersion.new(0)).
780
- append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s2, RubyEventStore::ExpectedVersion.new(1))
785
+ append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, version_none).
786
+ append_to_stream(b = SRecord.new(event_id: '34f88aca-aaba-4ca0-9256-8017b47528c5'), s2, version_none).
787
+ append_to_stream(c = SRecord.new(event_id: '8e61c864-ceae-4684-8726-97c34eb8fc4f'), s1, version_0).
788
+ append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s2, version_0).
789
+ append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s2, version_1)
781
790
 
782
791
  expect(read_stream_events_forward(repository, s1)).to eq [a,c]
783
792
  expect(read_stream_events_backward(repository, s1)).to eq [c,a]
@@ -785,18 +794,18 @@ RSpec.shared_examples :event_repository do |repository_class|
785
794
 
786
795
  it 'reads all stream linked events forward & backward' do
787
796
  skip unless test_link_events_to_stream
788
- s1, fs1, fs2 = RubyEventStore::Stream.new('stream'), RubyEventStore::Stream.new("flow"), RubyEventStore::Stream.new("other_flow")
797
+ s1, fs1, fs2 = stream, stream_flow, stream_other
789
798
  repository.
790
- append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, RubyEventStore::ExpectedVersion.none).
791
- append_to_stream(b = SRecord.new(event_id: '34f88aca-aaba-4ca0-9256-8017b47528c5'), s1, RubyEventStore::ExpectedVersion.new(0)).
792
- append_to_stream(c = SRecord.new(event_id: '8e61c864-ceae-4684-8726-97c34eb8fc4f'), s1, RubyEventStore::ExpectedVersion.new(1)).
793
- append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s1, RubyEventStore::ExpectedVersion.new(2)).
794
- append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s1, RubyEventStore::ExpectedVersion.new(3)).
795
- link_to_stream('7010d298-ab69-4bb1-9251-f3466b5d1282', fs1, RubyEventStore::ExpectedVersion.none).
796
- link_to_stream('34f88aca-aaba-4ca0-9256-8017b47528c5', fs2, RubyEventStore::ExpectedVersion.none).
797
- link_to_stream('8e61c864-ceae-4684-8726-97c34eb8fc4f', fs1, RubyEventStore::ExpectedVersion.new(0)).
798
- link_to_stream('30963ed9-6349-450b-ac9b-8ea50115b3bd', fs2, RubyEventStore::ExpectedVersion.new(0)).
799
- link_to_stream('5bdc58b7-e8a7-4621-afd6-ccb828d72457', fs2, RubyEventStore::ExpectedVersion.new(1))
799
+ append_to_stream(a = SRecord.new(event_id: '7010d298-ab69-4bb1-9251-f3466b5d1282'), s1, version_none).
800
+ append_to_stream(b = SRecord.new(event_id: '34f88aca-aaba-4ca0-9256-8017b47528c5'), s1, version_0).
801
+ append_to_stream(c = SRecord.new(event_id: '8e61c864-ceae-4684-8726-97c34eb8fc4f'), s1, version_1).
802
+ append_to_stream(d = SRecord.new(event_id: '30963ed9-6349-450b-ac9b-8ea50115b3bd'), s1, version_2).
803
+ append_to_stream(e = SRecord.new(event_id: '5bdc58b7-e8a7-4621-afd6-ccb828d72457'), s1, version_3).
804
+ link_to_stream('7010d298-ab69-4bb1-9251-f3466b5d1282', fs1, version_none).
805
+ link_to_stream('34f88aca-aaba-4ca0-9256-8017b47528c5', fs2, version_none).
806
+ link_to_stream('8e61c864-ceae-4684-8726-97c34eb8fc4f', fs1, version_0).
807
+ link_to_stream('30963ed9-6349-450b-ac9b-8ea50115b3bd', fs2, version_0).
808
+ link_to_stream('5bdc58b7-e8a7-4621-afd6-ccb828d72457', fs2, version_1)
800
809
 
801
810
  expect(read_stream_events_forward(repository, fs1)).to eq [a,c]
802
811
  expect(read_stream_events_backward(repository, fs1)).to eq [c,a]
@@ -816,7 +825,7 @@ RSpec.shared_examples :event_repository do |repository_class|
816
825
  868cac42-3d19-4b39-84e8-cd32d65c2445
817
826
  ].map { |id| SRecord.new(event_id: id) }
818
827
  events.each do |ev|
819
- repository.append_to_stream(ev, RubyEventStore::Stream.new(SecureRandom.uuid), RubyEventStore::ExpectedVersion.none)
828
+ repository.append_to_stream(ev, RubyEventStore::Stream.new(SecureRandom.uuid), version_none)
820
829
  end
821
830
 
822
831
  expect(read_all_streams_forward(repository, :head, 3)).to eq(events.first(3))
@@ -846,8 +855,8 @@ RSpec.shared_examples :event_repository do |repository_class|
846
855
  ].map { |id| SRecord.new(event_id: id) }
847
856
  events.each do |ev|
848
857
  repository.
849
- append_to_stream(ev, RubyEventStore::Stream.new(SecureRandom.uuid), RubyEventStore::ExpectedVersion.none).
850
- link_to_stream(ev.event_id, RubyEventStore::Stream.new(SecureRandom.uuid), RubyEventStore::ExpectedVersion.none)
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)
851
860
  end
852
861
 
853
862
  expect(read_all_streams_forward(repository, :head, 3)).to eq(events.first(3))
@@ -866,27 +875,27 @@ RSpec.shared_examples :event_repository do |repository_class|
866
875
  96c920b1-cdd0-40f4-907c-861b9fff7d02
867
876
  56404f79-0ba0-4aa0-8524-dc3436368ca0
868
877
  ].map{|id| SRecord.new(event_id: id) }
869
- repository.append_to_stream(events.first, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
870
- repository.append_to_stream(events.last, RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.new(0))
878
+ repository.append_to_stream(events.first, stream, version_none)
879
+ repository.append_to_stream(events.last, stream, version_0)
871
880
 
872
881
  expect(read_all_streams_forward(repository, "96c920b1-cdd0-40f4-907c-861b9fff7d02", 1)).to eq([events.last])
873
882
  expect(read_all_streams_backward(repository, "56404f79-0ba0-4aa0-8524-dc3436368ca0", 1)).to eq([events.first])
874
883
 
875
- expect(read_events_forward(repository, RubyEventStore::Stream.new('stream'), "96c920b1-cdd0-40f4-907c-861b9fff7d02", 1)).to eq([events.last])
876
- expect(read_events_backward(repository, RubyEventStore::Stream.new('stream'), "56404f79-0ba0-4aa0-8524-dc3436368ca0", 1)).to eq([events.first])
884
+ expect(read_events_forward(repository, stream, "96c920b1-cdd0-40f4-907c-861b9fff7d02", 1)).to eq([events.last])
885
+ expect(read_events_backward(repository, stream, "56404f79-0ba0-4aa0-8524-dc3436368ca0", 1)).to eq([events.first])
877
886
  end
878
887
 
879
888
  it 'does not allow same event twice in a stream' do
880
889
  repository.append_to_stream(
881
890
  SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
882
- RubyEventStore::Stream.new('stream'),
883
- RubyEventStore::ExpectedVersion.none
891
+ stream,
892
+ version_none
884
893
  )
885
894
  expect do
886
895
  repository.append_to_stream(
887
896
  SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
888
- RubyEventStore::Stream.new('stream'),
889
- RubyEventStore::ExpectedVersion.new(0)
897
+ stream,
898
+ version_0
890
899
  )
891
900
  end.to raise_error(RubyEventStore::EventDuplicatedInStream)
892
901
  end
@@ -894,14 +903,14 @@ RSpec.shared_examples :event_repository do |repository_class|
894
903
  it 'does not allow same event twice' do
895
904
  repository.append_to_stream(
896
905
  SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
897
- RubyEventStore::Stream.new('stream'),
898
- RubyEventStore::ExpectedVersion.none
906
+ stream,
907
+ version_none
899
908
  )
900
909
  expect do
901
910
  repository.append_to_stream(
902
911
  SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
903
- RubyEventStore::Stream.new("another"),
904
- RubyEventStore::ExpectedVersion.none
912
+ stream_other,
913
+ version_none
905
914
  )
906
915
  end.to raise_error(RubyEventStore::EventDuplicatedInStream)
907
916
  end
@@ -910,32 +919,32 @@ RSpec.shared_examples :event_repository do |repository_class|
910
919
  skip unless test_link_events_to_stream
911
920
  repository.append_to_stream([
912
921
  SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef"),
913
- ], RubyEventStore::Stream.new('stream'),
914
- RubyEventStore::ExpectedVersion.none
915
- ).link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
922
+ ], stream,
923
+ version_none
924
+ ).link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", stream_flow, version_none)
916
925
  expect do
917
- repository.link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.new(0))
926
+ repository.link_to_stream("a1b49edb-7636-416f-874a-88f94b859bef", stream_flow, version_0)
918
927
  end.to raise_error(RubyEventStore::EventDuplicatedInStream)
919
928
  end
920
929
 
921
930
  it 'allows appending to GLOBAL_STREAM explicitly' do
922
931
  event = SRecord.new(event_id: "df8b2ba3-4e2c-4888-8d14-4364855fa80e")
923
- repository.append_to_stream(event, RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM), RubyEventStore::ExpectedVersion.any)
932
+ repository.append_to_stream(event, global_stream, version_any)
924
933
 
925
934
  expect(read_all_streams_forward(repository, :head, 10)).to eq([event])
926
935
  end
927
936
 
928
937
  specify "events not persisted if append failed" do
929
938
  repository.append_to_stream([
930
- SRecord.new(event_id: SecureRandom.uuid),
931
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
939
+ SRecord.new,
940
+ ], stream, version_none)
932
941
 
933
942
  expect do
934
943
  repository.append_to_stream([
935
944
  SRecord.new(
936
945
  event_id: '9bedf448-e4d0-41a3-a8cd-f94aec7aa763'
937
946
  ),
938
- ], RubyEventStore::Stream.new('stream'), RubyEventStore::ExpectedVersion.none)
947
+ ], stream, version_none)
939
948
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
940
949
  expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
941
950
  end
@@ -943,8 +952,8 @@ RSpec.shared_examples :event_repository do |repository_class|
943
952
  specify 'reading particular event' do
944
953
  test_event = SRecord.new(event_id: "941cd8f5-b3f9-47af-b4e4-07f8cea37467")
945
954
  repository.
946
- append_to_stream(SRecord.new, RubyEventStore::Stream.new("test"), RubyEventStore::ExpectedVersion.none).
947
- append_to_stream(test_event, RubyEventStore::Stream.new("test"), RubyEventStore::ExpectedVersion.new(0))
955
+ append_to_stream(SRecord.new, stream_test, version_none).
956
+ append_to_stream(test_event, stream_test, version_0)
948
957
 
949
958
  expect(repository.read_event("941cd8f5-b3f9-47af-b4e4-07f8cea37467")).to eq(test_event)
950
959
  end
@@ -962,7 +971,7 @@ RSpec.shared_examples :event_repository do |repository_class|
962
971
  specify 'linking non-existent event' do
963
972
  skip unless test_link_events_to_stream
964
973
  expect do
965
- repository.link_to_stream('72922e65-1b32-4e97-8023-03ae81dd3a27', RubyEventStore::Stream.new("flow"), RubyEventStore::ExpectedVersion.none)
974
+ repository.link_to_stream('72922e65-1b32-4e97-8023-03ae81dd3a27', stream_flow, version_none)
966
975
  end.to raise_error do |err|
967
976
  expect(err).to be_a(RubyEventStore::EventNotFound)
968
977
  expect(err.event_id).to eq('72922e65-1b32-4e97-8023-03ae81dd3a27')
@@ -971,7 +980,6 @@ RSpec.shared_examples :event_repository do |repository_class|
971
980
  end
972
981
 
973
982
  specify 'read returns enumerator' do
974
- specification = RubyEventStore::Specification.new(repository)
975
983
  expect(repository.read(specification.result)).to be_kind_of(Enumerator)
976
984
  end
977
985
 
@@ -985,8 +993,110 @@ RSpec.shared_examples :event_repository do |repository_class|
985
993
 
986
994
  repository.append_to_stream(
987
995
  event = SRecord.new(data: binary, metadata: binary),
988
- RubyEventStore::Stream.new('stream'),
996
+ stream,
997
+ version_none
998
+ )
999
+ end
1000
+
1001
+ specify do
1002
+ events = Array.new(400) { SRecord.new }
1003
+ repository.append_to_stream(
1004
+ events[200...400],
1005
+ RubyEventStore::Stream.new("Foo"),
1006
+ RubyEventStore::ExpectedVersion.none
1007
+ )
1008
+ repository.append_to_stream(
1009
+ events[0...200],
1010
+ RubyEventStore::Stream.new("Dummy"),
989
1011
  RubyEventStore::ExpectedVersion.none
990
1012
  )
1013
+
1014
+ batches = repository.read(specification.stream("Dummy").in_batches.result).to_a
1015
+ expect(batches.size).to eq(2)
1016
+ expect(batches[0].size).to eq(100)
1017
+ expect(batches[0]).to eq(events[0..99])
1018
+ end
1019
+
1020
+ specify do
1021
+ events = Array.new(200) { SRecord.new }
1022
+ repository.append_to_stream(
1023
+ events,
1024
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1025
+ RubyEventStore::ExpectedVersion.any
1026
+ )
1027
+
1028
+ batches = repository.read(specification.in_batches.result).to_a
1029
+ expect(batches.size).to eq(2)
1030
+ expect(batches[0].size).to eq(100)
1031
+ expect(batches[0]).to eq(events[0..99])
1032
+ end
1033
+
1034
+ specify do
1035
+ events = Array.new(200) { SRecord.new }
1036
+ repository.append_to_stream(
1037
+ events,
1038
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1039
+ RubyEventStore::ExpectedVersion.any
1040
+ )
1041
+
1042
+ expect(repository.read(specification.in_batches(200).result).to_a.size).to eq(1)
1043
+ end
1044
+
1045
+ specify do
1046
+ events = Array.new(200) { SRecord.new }
1047
+ repository.append_to_stream(
1048
+ events,
1049
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1050
+ RubyEventStore::ExpectedVersion.any
1051
+ )
1052
+
1053
+ batches = repository.read(specification.limit(199).in_batches.result).to_a
1054
+ expect(batches.size).to eq(2)
1055
+ expect(batches[0].size).to eq(100)
1056
+ expect(batches[0]).to eq(events[0..99])
1057
+ expect(batches[1].size).to eq(99)
1058
+ expect(batches[1]).to eq(events[100..198])
1059
+ end
1060
+
1061
+ specify do
1062
+ events = Array.new(200) { SRecord.new }
1063
+ repository.append_to_stream(
1064
+ events,
1065
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1066
+ RubyEventStore::ExpectedVersion.any
1067
+ )
1068
+
1069
+ batches = repository.read(specification.limit(99).in_batches.result).to_a
1070
+ expect(batches.size).to eq(1)
1071
+ expect(batches[0].size).to eq(99)
1072
+ expect(batches[0]).to eq(events[0..98])
1073
+ end
1074
+
1075
+ specify do
1076
+ events = Array.new(200) { SRecord.new }
1077
+ repository.append_to_stream(
1078
+ events,
1079
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1080
+ RubyEventStore::ExpectedVersion.any
1081
+ )
1082
+
1083
+ batches = repository.read(specification.backward.limit(99).in_batches.result).to_a
1084
+ expect(batches.size).to eq(1)
1085
+ expect(batches[0].size).to eq(99)
1086
+ expect(batches[0]).to eq(events[101..-1].reverse)
1087
+ end
1088
+
1089
+ specify do
1090
+ events = Array.new(200) { SRecord.new }
1091
+ repository.append_to_stream(
1092
+ events,
1093
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1094
+ RubyEventStore::ExpectedVersion.any
1095
+ )
1096
+
1097
+ batches = repository.read(specification.from(events[100].event_id).limit(99).in_batches.result).to_a
1098
+ expect(batches.size).to eq(1)
1099
+ expect(batches[0].size).to eq(99)
1100
+ expect(batches[0]).to eq(events[101..199])
991
1101
  end
992
1102
  end