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