synapse-core 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/synapse/command.rb +2 -0
- data/lib/synapse/command/callbacks/future.rb +50 -0
- data/lib/synapse/command/command_callback.rb +0 -47
- data/lib/synapse/command/message.rb +1 -1
- data/lib/synapse/common.rb +1 -0
- data/lib/synapse/common/concurrency/executor.rb +13 -0
- data/lib/synapse/common/message.rb +9 -2
- data/lib/synapse/common/message_builder.rb +5 -1
- data/lib/synapse/configuration.rb +1 -0
- data/lib/synapse/configuration/component/command_bus/async_command_bus.rb +2 -8
- data/lib/synapse/configuration/component/event_sourcing.rb +3 -3
- data/lib/synapse/configuration/component/event_sourcing/repository.rb +19 -2
- data/lib/synapse/configuration/component/event_sourcing/{aggregate_snapshot_taker.rb → snapshot/aggregate_taker.rb} +4 -4
- data/lib/synapse/configuration/component/event_sourcing/{interval_snapshot_policy.rb → snapshot/interval_policy.rb} +0 -0
- data/lib/synapse/configuration/component/mixin/thread_pool.rb +26 -0
- data/lib/synapse/domain/message.rb +0 -24
- data/lib/synapse/domain/message_builder.rb +0 -9
- data/lib/synapse/event_sourcing.rb +1 -1
- data/lib/synapse/event_sourcing/aggregate_root.rb +2 -1
- data/lib/synapse/event_sourcing/caching.rb +66 -0
- data/lib/synapse/event_sourcing/repository.rb +22 -15
- data/lib/synapse/event_sourcing/snapshot/aggregate_taker.rb +8 -9
- data/lib/synapse/event_sourcing/snapshot/policy.rb +1 -0
- data/lib/synapse/event_sourcing/snapshot/taker.rb +31 -2
- data/lib/synapse/repository/repository.rb +18 -4
- data/lib/synapse/repository/simple_repository.rb +8 -17
- data/lib/synapse/serialization/converter.rb +2 -2
- data/lib/synapse/serialization/converter/identity.rb +2 -2
- data/lib/synapse/serialization/converter/json.rb +3 -3
- data/lib/synapse/serialization/converter/ox.rb +3 -3
- data/lib/synapse/serialization/message/metadata.rb +2 -2
- data/lib/synapse/serialization/message/serialization_aware.rb +2 -2
- data/lib/synapse/serialization/message/serialized_message.rb +7 -24
- data/lib/synapse/serialization/message/serialized_message_builder.rb +4 -4
- data/lib/synapse/uow.rb +0 -1
- data/lib/synapse/uow/nesting.rb +2 -2
- data/lib/synapse/uow/uow.rb +12 -13
- data/lib/synapse/version.rb +1 -1
- data/test/configuration/component/event_sourcing/repository_test.rb +24 -1
- data/test/event_sourcing/caching_test.rb +118 -0
- data/test/event_sourcing/repository_test.rb +2 -1
- data/test/event_sourcing/snapshot/aggregate_taker_test.rb +46 -16
- data/test/repository/locking_test.rb +1 -10
- data/test/serialization/serializer/attribute_test.rb +51 -0
- data/test/uow/uow_test.rb +9 -12
- metadata +12 -9
- data/lib/synapse/event_sourcing/storage_listener.rb +0 -34
- data/lib/synapse/uow/storage_listener.rb +0 -14
- data/test/event_sourcing/storage_listener_test.rb +0 -81
@@ -1,34 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module EventSourcing
|
3
|
-
# Storage listener that commits aggregates to an event store
|
4
|
-
class EventSourcedStorageListener < UnitOfWork::StorageListener
|
5
|
-
# @param [EventStore] event_store
|
6
|
-
# @param [LockManager] lock_manager
|
7
|
-
# @param [Array] stream_decorators
|
8
|
-
# @param [String] type_identifier
|
9
|
-
# @return [undefined]
|
10
|
-
def initialize(event_store, lock_manager, stream_decorators, type_identifier)
|
11
|
-
@event_store = event_store
|
12
|
-
@lock_manager = lock_manager
|
13
|
-
@stream_decorators = stream_decorators
|
14
|
-
@type_identifier = type_identifier
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param [AggregateRoot] aggregate
|
18
|
-
# @return [undefined]
|
19
|
-
def store(aggregate)
|
20
|
-
if aggregate.version and !@lock_manager.validate_lock aggregate
|
21
|
-
raise Repository::ConflictingModificationError
|
22
|
-
end
|
23
|
-
|
24
|
-
stream = aggregate.uncommitted_events
|
25
|
-
@stream_decorators.reverse_each do |decorator|
|
26
|
-
stream = decorator.decorate_for_append @type_identifier, aggregate, stream
|
27
|
-
end
|
28
|
-
|
29
|
-
@event_store.append_events @type_identifier, stream
|
30
|
-
aggregate.mark_committed
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module UnitOfWork
|
3
|
-
# Represents a mechanism for a unit of work to commit an aggregate to an underlying store
|
4
|
-
# @abstract
|
5
|
-
class StorageListener
|
6
|
-
# Commits the given aggregate to the underlying storage mechanism
|
7
|
-
#
|
8
|
-
# @abstract
|
9
|
-
# @param [AggregateRoot] aggregate
|
10
|
-
# @return [undefined]
|
11
|
-
def store(aggregate); end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Synapse
|
4
|
-
module EventSourcing
|
5
|
-
|
6
|
-
class EventSourcedStorageListenerTest < Test::Unit::TestCase
|
7
|
-
should 'append uncommitted aggregate events to the event store' do
|
8
|
-
event_store = Object.new
|
9
|
-
lock_manager = Repository::NullLockManager.new
|
10
|
-
decorators = Array.new
|
11
|
-
type_identifier = StubAggregate.to_s.demodulize
|
12
|
-
aggregate = Object.new
|
13
|
-
|
14
|
-
decorator = Object.new
|
15
|
-
decorators.push decorator
|
16
|
-
|
17
|
-
original_stream = Domain::DomainEventStream.new
|
18
|
-
decorated_stream = Domain::DomainEventStream.new
|
19
|
-
|
20
|
-
mock(aggregate).version
|
21
|
-
mock(aggregate).uncommitted_events do
|
22
|
-
original_stream
|
23
|
-
end
|
24
|
-
mock(aggregate).mark_committed
|
25
|
-
|
26
|
-
mock(decorator).decorate_for_append(type_identifier, aggregate, original_stream) do
|
27
|
-
decorated_stream
|
28
|
-
end
|
29
|
-
|
30
|
-
mock(event_store).append_events(type_identifier, decorated_stream)
|
31
|
-
|
32
|
-
listener = EventSourcedStorageListener.new event_store, lock_manager, decorators, type_identifier
|
33
|
-
listener.store aggregate
|
34
|
-
end
|
35
|
-
|
36
|
-
should 'validate lock if the aggregate is not new' do
|
37
|
-
event_store = Object.new
|
38
|
-
lock_manager = Object.new
|
39
|
-
decorators = Array.new
|
40
|
-
type_identifier = StubAggregate.to_s.demodulize
|
41
|
-
aggregate = StubAggregate.new 123
|
42
|
-
|
43
|
-
mock(aggregate).version do
|
44
|
-
123
|
45
|
-
end
|
46
|
-
|
47
|
-
mock(lock_manager).validate_lock(aggregate) do
|
48
|
-
true
|
49
|
-
end
|
50
|
-
|
51
|
-
mock(event_store).append_events(type_identifier, anything)
|
52
|
-
|
53
|
-
listener = EventSourcedStorageListener.new event_store, lock_manager, decorators, type_identifier
|
54
|
-
listener.store aggregate
|
55
|
-
end
|
56
|
-
|
57
|
-
should 'raise an exception if the aggregate is not new and the lock is invalid' do
|
58
|
-
event_store = Object.new
|
59
|
-
lock_manager = Object.new
|
60
|
-
decorators = Array.new
|
61
|
-
type_identifier = StubAggregate.to_s.demodulize
|
62
|
-
aggregate = Object.new
|
63
|
-
|
64
|
-
mock(aggregate).version do
|
65
|
-
123
|
66
|
-
end
|
67
|
-
|
68
|
-
mock(lock_manager).validate_lock(aggregate) do
|
69
|
-
false
|
70
|
-
end
|
71
|
-
|
72
|
-
listener = EventSourcedStorageListener.new event_store, lock_manager, decorators, type_identifier
|
73
|
-
|
74
|
-
assert_raise Repository::ConflictingModificationError do
|
75
|
-
listener.store aggregate
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|