synapse-core 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/lib/synapse/command/async_command_bus.rb +41 -0
  2. data/lib/synapse/command/command_callback.rb +49 -2
  3. data/lib/synapse/command/command_handler.rb +2 -0
  4. data/lib/synapse/command/filters/validation.rb +2 -2
  5. data/lib/synapse/command/gateway/interval_retry_scheduler.rb +75 -0
  6. data/lib/synapse/command/gateway/retry_scheduler.rb +26 -0
  7. data/lib/synapse/command/gateway/retrying_callback.rb +46 -0
  8. data/lib/synapse/command/gateway.rb +56 -11
  9. data/lib/synapse/command/interceptor_chain.rb +2 -2
  10. data/lib/synapse/command/interceptors/serialization.rb +2 -2
  11. data/lib/synapse/command/message.rb +16 -0
  12. data/lib/synapse/command/simple_command_bus.rb +6 -2
  13. data/lib/synapse/command/wiring.rb +3 -3
  14. data/lib/synapse/command.rb +7 -1
  15. data/lib/synapse/common/concurrency/identifier_lock.rb +2 -17
  16. data/lib/synapse/common/concurrency/public_lock.rb +8 -9
  17. data/lib/synapse/common/errors.rb +1 -1
  18. data/lib/synapse/common/message.rb +2 -6
  19. data/lib/synapse/common.rb +9 -0
  20. data/lib/synapse/configuration/component/command_bus/async_command_bus.rb +41 -0
  21. data/lib/synapse/configuration/component/command_bus/gateway.rb +38 -0
  22. data/lib/synapse/configuration/component/command_bus/simple_command_bus.rb +81 -0
  23. data/lib/synapse/configuration/component/command_bus.rb +35 -0
  24. data/lib/synapse/configuration/component/event_bus/simple_event_bus.rb +41 -0
  25. data/lib/synapse/configuration/component/event_bus.rb +15 -0
  26. data/lib/synapse/configuration/component/event_sourcing/repository.rb +62 -0
  27. data/lib/synapse/configuration/component/event_sourcing.rb +15 -0
  28. data/lib/synapse/configuration/component/repository/locking_repository.rb +85 -0
  29. data/lib/synapse/configuration/component/repository/simple_repository.rb +31 -0
  30. data/lib/synapse/configuration/component/repository.rb +15 -0
  31. data/lib/synapse/configuration/component/serialization/converter_factory.rb +50 -0
  32. data/lib/synapse/configuration/component/serialization/serializer.rb +90 -0
  33. data/lib/synapse/configuration/component/serialization.rb +25 -0
  34. data/lib/synapse/configuration/component/uow/unit_factory.rb +51 -0
  35. data/lib/synapse/configuration/component/uow.rb +22 -0
  36. data/lib/synapse/configuration/component/upcasting/upcaster_chain.rb +61 -0
  37. data/lib/synapse/configuration/component/upcasting.rb +15 -0
  38. data/lib/synapse/configuration/container.rb +80 -0
  39. data/lib/synapse/configuration/container_builder.rb +108 -0
  40. data/lib/synapse/configuration/definition.rb +31 -0
  41. data/lib/synapse/configuration/definition_builder.rb +138 -0
  42. data/lib/synapse/configuration/dependent.rb +31 -0
  43. data/lib/synapse/configuration/ext.rb +35 -0
  44. data/lib/synapse/configuration.rb +32 -0
  45. data/lib/synapse/domain/aggregate_root.rb +25 -26
  46. data/lib/synapse/domain/event_container.rb +5 -5
  47. data/lib/synapse/domain/message.rb +16 -0
  48. data/lib/synapse/event_bus/event_listener.rb +2 -0
  49. data/lib/synapse/event_bus/event_publisher.rb +19 -0
  50. data/lib/synapse/event_bus/simple_event_bus.rb +21 -30
  51. data/lib/synapse/event_bus/wiring.rb +5 -4
  52. data/lib/synapse/event_bus.rb +1 -1
  53. data/lib/synapse/event_sourcing/aggregate_root.rb +6 -4
  54. data/lib/synapse/process_manager/container_resource_injector.rb +18 -0
  55. data/lib/synapse/process_manager/pessimistic_lock_manager.rb +1 -1
  56. data/lib/synapse/process_manager/process.rb +4 -0
  57. data/lib/synapse/process_manager/process_factory.rb +3 -3
  58. data/lib/synapse/process_manager/repository/in_memory.rb +1 -1
  59. data/lib/synapse/process_manager/wiring/process.rb +6 -6
  60. data/lib/synapse/process_manager/wiring/process_manager.rb +8 -8
  61. data/lib/synapse/process_manager.rb +2 -0
  62. data/lib/synapse/repository/locking.rb +5 -3
  63. data/lib/synapse/repository/optimistic_lock_manager.rb +2 -7
  64. data/lib/synapse/repository/pessimistic_lock_manager.rb +3 -3
  65. data/lib/synapse/repository/repository.rb +2 -2
  66. data/lib/synapse/repository/simple_repository.rb +69 -0
  67. data/lib/synapse/repository.rb +1 -0
  68. data/lib/synapse/serialization/converter/chain.rb +2 -2
  69. data/lib/synapse/serialization/converter_factory.rb +2 -2
  70. data/lib/synapse/serialization/lazy_object.rb +2 -2
  71. data/lib/synapse/serialization/message/serialization_aware_message.rb +3 -3
  72. data/lib/synapse/serialization/message/serialized_message.rb +6 -10
  73. data/lib/synapse/serialization/message/serialized_message_builder.rb +4 -4
  74. data/lib/synapse/serialization/message/serialized_object_cache.rb +2 -2
  75. data/lib/synapse/serialization/message/serializer.rb +2 -2
  76. data/lib/synapse/serialization/revision_resolver.rb +3 -3
  77. data/lib/synapse/serialization/serialized_object.rb +2 -2
  78. data/lib/synapse/serialization/serialized_type.rb +2 -2
  79. data/lib/synapse/serialization/serializer/attribute.rb +2 -2
  80. data/lib/synapse/serialization/serializer/marshal.rb +2 -2
  81. data/lib/synapse/serialization/serializer/oj.rb +2 -2
  82. data/lib/synapse/serialization/serializer/ox.rb +2 -2
  83. data/lib/synapse/serialization/serializer.rb +2 -2
  84. data/lib/synapse/uow/factory.rb +2 -2
  85. data/lib/synapse/uow/listener_collection.rb +2 -2
  86. data/lib/synapse/uow/nesting.rb +9 -2
  87. data/lib/synapse/uow/provider.rb +2 -2
  88. data/lib/synapse/uow/uow.rb +8 -2
  89. data/lib/synapse/upcasting/{chain.rb → upcaster_chain.rb} +0 -0
  90. data/lib/synapse/upcasting.rb +1 -1
  91. data/lib/synapse/version.rb +1 -1
  92. data/lib/synapse/wiring/message_wiring.rb +31 -0
  93. data/lib/synapse.rb +2 -14
  94. data/test/auditing/data_provider_test.rb +2 -2
  95. data/test/auditing/dispatch_interceptor_test.rb +1 -1
  96. data/test/auditing/unit_listener_test.rb +3 -3
  97. data/test/command/async_command_bus_test.rb +49 -0
  98. data/test/command/duplication_test.rb +2 -2
  99. data/test/command/gateway/interval_retry_scheduler_test.rb +42 -0
  100. data/test/command/gateway/retrying_callback_test.rb +57 -0
  101. data/test/command/gateway_test.rb +41 -7
  102. data/test/command/interceptor_chain_test.rb +1 -1
  103. data/test/command/message_test.rb +17 -0
  104. data/test/command/serialization_test.rb +2 -2
  105. data/test/command/simple_command_bus_test.rb +7 -7
  106. data/test/command/validation_test.rb +3 -3
  107. data/test/command/wiring_test.rb +3 -3
  108. data/test/common/concurrency/identifier_lock_test.rb +2 -13
  109. data/test/common/concurrency/public_lock_test.rb +6 -6
  110. data/test/{duplication_test.rb → common/duplication_test.rb} +3 -3
  111. data/test/configuration/component/command_bus/async_command_bus_test.rb +36 -0
  112. data/test/configuration/component/command_bus/simple_command_bus_test.rb +57 -0
  113. data/test/configuration/component/event_bus/simple_event_bus_test.rb +58 -0
  114. data/test/configuration/component/serialization/converter_factory_test.rb +48 -0
  115. data/test/configuration/component/serialization/serializer_test.rb +78 -0
  116. data/test/configuration/component/uow/unit_factory_test.rb +46 -0
  117. data/test/configuration/container_builder_test.rb +47 -0
  118. data/test/configuration/container_test.rb +88 -0
  119. data/test/configuration/definition_builder_test.rb +126 -0
  120. data/test/configuration/definition_test.rb +41 -0
  121. data/test/configuration/dependent_test.rb +30 -0
  122. data/test/configuration/ext_test.rb +19 -0
  123. data/test/configuration/fixtures/dependent.rb +10 -0
  124. data/test/domain/aggregate_root_test.rb +5 -5
  125. data/test/domain/message_test.rb +15 -3
  126. data/test/domain/stream_test.rb +2 -2
  127. data/test/event_bus/publisher_test.rb +29 -0
  128. data/test/event_bus/wiring_test.rb +1 -1
  129. data/test/event_sourcing/aggregate_factory_test.rb +12 -6
  130. data/test/event_sourcing/aggregate_root_test.rb +4 -4
  131. data/test/event_sourcing/entity_test.rb +10 -9
  132. data/test/event_sourcing/repository_test.rb +6 -6
  133. data/test/event_sourcing/storage_listener_test.rb +8 -4
  134. data/test/event_store/in_memory_test.rb +3 -3
  135. data/test/process_manager/container_resource_injector_test.rb +19 -0
  136. data/test/process_manager/correlation_set_test.rb +2 -2
  137. data/test/process_manager/correlation_test.rb +2 -2
  138. data/test/process_manager/in_memory_test.rb +3 -3
  139. data/test/process_manager/process_factory_test.rb +2 -2
  140. data/test/process_manager/process_test.rb +3 -3
  141. data/test/process_manager/simple_process_manager_test.rb +5 -5
  142. data/test/process_manager/wiring/process_manager_test.rb +4 -4
  143. data/test/process_manager/wiring/process_test.rb +2 -2
  144. data/test/repository/locking_test.rb +4 -4
  145. data/test/repository/optimistic_test.rb +2 -2
  146. data/test/repository/pessimistic_test.rb +1 -1
  147. data/test/repository/simple_repository_test.rb +79 -0
  148. data/test/support/countdown_latch.rb +18 -0
  149. data/test/test_helper.rb +6 -3
  150. data/test/upcasting/data_test.rb +31 -0
  151. metadata +84 -25
  152. data/lib/synapse/event_bus/event_listener_proxy.rb +0 -12
  153. data/lib/synapse/partitioning/memory_queue_reader.rb +0 -31
  154. data/lib/synapse/partitioning/memory_queue_writer.rb +0 -19
  155. data/lib/synapse/partitioning/message_receipt.rb +0 -25
  156. data/lib/synapse/partitioning/packing/json_packer.rb +0 -93
  157. data/lib/synapse/partitioning/packing/json_unpacker.rb +0 -83
  158. data/lib/synapse/partitioning/packing.rb +0 -27
  159. data/lib/synapse/partitioning/queue_reader.rb +0 -32
  160. data/lib/synapse/partitioning/queue_writer.rb +0 -17
  161. data/lib/synapse/partitioning.rb +0 -18
  162. data/test/partitioning/memory_test.rb +0 -34
  163. data/test/partitioning/packing/json_test.rb +0 -62
@@ -0,0 +1,126 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module Configuration
5
+ class DefinitionBuilderTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @container = Container.new
9
+ end
10
+
11
+ should 'build a definition with just an identifier' do
12
+ DefinitionBuilder.build @container, :some_id do
13
+ # we'll pass here
14
+ end
15
+ assert @container.registered? :some_id
16
+ end
17
+
18
+ should 'build a definition using an identifier set in the block' do
19
+ DefinitionBuilder.build @container do
20
+ identified_by :other_id
21
+ end
22
+ assert @container.registered? :other_id
23
+ end
24
+
25
+ should 'build a definition using tags set in the block' do
26
+ reference = Object.new
27
+
28
+ DefinitionBuilder.build @container, :derp_service do
29
+ tag :one, :two
30
+ use_instance reference
31
+ end
32
+
33
+ assert @container.registered? :derp_service
34
+ assert_equal [reference], @container.resolve_tagged(:one)
35
+ assert_equal [reference], @container.resolve_tagged(:two)
36
+ assert_equal [], @container.resolve_tagged(:three)
37
+ end
38
+
39
+ should 'build a prototype definition using a factory' do
40
+ DefinitionBuilder.build @container, :keygen do
41
+ as_prototype
42
+ use_factory do
43
+ SecureRandom.uuid
44
+ end
45
+ end
46
+
47
+ first = @container.resolve :keygen
48
+ second = @container.resolve :keygen
49
+
50
+ refute_equal first, second
51
+ end
52
+
53
+ should 'build a singleton definition using a factory' do
54
+ DefinitionBuilder.build @container, :static_keygen do
55
+ as_singleton
56
+ use_factory do
57
+ SecureRandom.uuid
58
+ end
59
+ end
60
+
61
+ first = @container.resolve :static_keygen
62
+ second = @container.resolve :static_keygen
63
+
64
+ assert_equal first, second
65
+ end
66
+
67
+ should 'delegate resolution to the service container' do
68
+ DefinitionBuilder.build @container, :some_dependency do
69
+ use_instance 123
70
+ end
71
+
72
+ DefinitionBuilder.build @container, :dependent do
73
+ use_factory do
74
+ resolve :some_dependency
75
+ end
76
+ end
77
+
78
+ value = @container.resolve :dependent
79
+ assert_equal 123, value
80
+
81
+ DefinitionBuilder.build @container, :self_dependent do
82
+ use_factory do
83
+ resolve Hash.new
84
+ end
85
+ end
86
+
87
+ value = @container.resolve :self_dependent
88
+ assert value.is_a? Hash
89
+ end
90
+
91
+ should 'delegate tag resolution to the service container' do
92
+ DefinitionBuilder.build @container, :some_tagged_dependency do
93
+ use_instance 123
94
+ tag :dependency
95
+ end
96
+
97
+ DefinitionBuilder.build @container, :dependent do
98
+ use_factory do
99
+ resolve_tagged :dependency
100
+ end
101
+ end
102
+
103
+ value = @container.resolve :dependent
104
+ assert_equal [123], value
105
+ end
106
+
107
+ should 'delegate building child services to another builder' do
108
+ DefinitionBuilder.build @container, :outside do
109
+ build_composite do
110
+ identified_by :inside
111
+ end
112
+ end
113
+
114
+ assert @container.registered? :outside
115
+ assert @container.registered? :inside
116
+ end
117
+
118
+ should 'raise an exception if no identifier is set when registering with the container' do
119
+ assert_raise ConfigurationError do
120
+ DefinitionBuilder.build @container
121
+ end
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module Configuration
5
+ class DefinitionTest < Test::Unit::TestCase
6
+
7
+ should 'call the defrred factory every time if prototype' do
8
+ factory_invoked = 0
9
+ factory = proc do
10
+ factory_invoked += 1
11
+ end
12
+
13
+ definition = Definition.new Set.new, true, factory, nil
14
+ definition.resolve
15
+ definition.resolve
16
+ assert_equal 2, factory_invoked
17
+ end
18
+
19
+ should 'call the deferred factory only once if singleton' do
20
+ factory_invoked = 0
21
+ factory = proc do
22
+ factory_invoked += 1
23
+ end
24
+
25
+ definition = Definition.new Set.new, false, factory, nil
26
+ definition.resolve
27
+ definition.resolve
28
+ assert_equal 1, factory_invoked
29
+ end
30
+
31
+ should 'resolve to an instance if one is provided' do
32
+ instance = Object.new
33
+
34
+ # Singleton service definition w/ late instance
35
+ definition = Definition.new Set.new, false, nil, instance
36
+ assert_same instance, definition.resolve
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+ require 'configuration/fixtures/dependent'
3
+
4
+ module Synapse
5
+ module Configuration
6
+ class DependentTest < Test::Unit::TestCase
7
+
8
+ should 'create accessors for injectable attributes' do
9
+ dependent = ExampleDependent.new
10
+
11
+ service_a = Object.new
12
+ service_b = Object.new
13
+
14
+ dependent.service_a = service_a
15
+ dependent.some_service = service_b
16
+
17
+ assert_same service_a, dependent.service_a
18
+ assert_same service_b, dependent.some_service
19
+ end
20
+
21
+ should 'track which services to inject in which attributes' do
22
+ dependencies = ExampleDependent.dependencies
23
+
24
+ assert_equal :service_a, dependencies[:service_a]
25
+ assert_equal :some_service, dependencies[:service_b]
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module Configuration
5
+ class ExtensionTest < Test::Unit::TestCase
6
+ should 'delegate building to the service container' do
7
+ reference = Object.new
8
+
9
+ Synapse.build do
10
+ factory :test_service do
11
+ reference
12
+ end
13
+ end
14
+
15
+ assert_same reference, Synapse.container[:test_service]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ExampleDependent
4
+ include Dependent
5
+
6
+ depends_on :service_a
7
+ depends_on :service_b, :attribute => :some_service
8
+ end
9
+ end
10
+ end
@@ -9,7 +9,7 @@ module Synapse
9
9
  @person = Person.new 123, 'Fry'
10
10
  end
11
11
 
12
- def test_publish_events
12
+ should 'track published events' do
13
13
  assert_equal 0, @person.uncommitted_event_count
14
14
 
15
15
  @person.change_name 'Leela'
@@ -27,20 +27,20 @@ module Synapse
27
27
  assert_equal events, @person.uncommitted_events.to_a
28
28
  end
29
29
 
30
- def test_mark_committed
30
+ should 'handle being marked committed' do
31
31
  @person.change_name 'Bender'
32
32
  @person.mark_committed
33
33
 
34
34
  assert_equal 0, @person.uncommitted_event_count
35
35
  end
36
36
 
37
- def test_mark_deleted
37
+ should 'handle being marked for deletion' do
38
38
  @person.delete
39
39
 
40
40
  assert @person.deleted?
41
41
  end
42
42
 
43
- def test_identifier_not_initialized
43
+ should 'raise an exception if identifier not initialized, but events are applied' do
44
44
  p = Person.new nil, nil
45
45
 
46
46
  assert_raise AggregateIdentifierNotInitializedError do
@@ -48,7 +48,7 @@ module Synapse
48
48
  end
49
49
  end
50
50
 
51
- def test_empty_uncommitted_events
51
+ should 'return an empty domain event stream if no events have been published' do
52
52
  assert @person.uncommitted_events.end?
53
53
  end
54
54
 
@@ -2,6 +2,18 @@ require 'test_helper'
2
2
 
3
3
  module Synapse
4
4
  module Domain
5
+ class EventMessageTest < Test::Unit::TestCase
6
+ should 'wrap event objects into event messages' do
7
+ event = Object.new
8
+ event_message = EventMessage.build
9
+
10
+ assert_same event_message, EventMessage.as_message(event_message)
11
+
12
+ wrapped = EventMessage.as_message(event)
13
+ assert_same event, wrapped.payload
14
+ end
15
+ end
16
+
5
17
  class DomainEventMessageTest < Test::Unit::TestCase
6
18
  def setup
7
19
  @payload = OpenStruct.new
@@ -15,7 +27,7 @@ module Synapse
15
27
  end
16
28
  end
17
29
 
18
- def test_initialize
30
+ should 'populate fields with sensible defaults' do
19
31
  # ensure empty fields were populated with default values
20
32
  assert @message.id
21
33
  assert @message.metadata
@@ -28,7 +40,7 @@ module Synapse
28
40
  assert_equal @sequence_number, @message.sequence_number
29
41
  end
30
42
 
31
- def test_and_metadata
43
+ should 'create a complete copy of itself when merging metadata' do
32
44
  additional_metadata_a = { foo: 'bar' }
33
45
  additional_metadata_b = { baz: 'qux' }
34
46
 
@@ -46,7 +58,7 @@ module Synapse
46
58
  assert_equal additional_metadata_a.merge(additional_metadata_b), merged.metadata
47
59
  end
48
60
 
49
- def test_with_metadata
61
+ should 'create a complete copy of itself when replacing metadata' do
50
62
  additional_metadata_a = { foo: 'bar' }
51
63
  additional_metadata_b = { baz: 'qux' }
52
64
 
@@ -12,12 +12,12 @@ module Synapse
12
12
  @stream = SimpleDomainEventStream.new @events
13
13
  end
14
14
 
15
- def test_peek
15
+ should 'support peeking without moving the pointer forward' do
16
16
  assert_same @events.at(0), @stream.peek
17
17
  assert_same @events.at(0), @stream.peek
18
18
  end
19
19
 
20
- def test_end_of_stream
20
+ should 'raise an exception when the end of the stream is reached' do
21
21
  @stream.next_event
22
22
  @stream.next_event
23
23
 
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module EventBus
5
+ class EventPublisherTest < Test::Unit::TestCase
6
+ should 'wrap event objects in messages before they are published' do
7
+ event_bus = Object.new
8
+
9
+ mock(event_bus).publish(is_a(Domain::EventMessage)) do |message|
10
+ assert message.payload.is_a? TestEvent
11
+ end
12
+
13
+ publisher = ExampleEventPublisher.new
14
+ publisher.event_bus = event_bus
15
+ publisher.do_something
16
+ end
17
+ end
18
+
19
+ class ExampleEventPublisher
20
+ include EventPublisher
21
+
22
+ def do_something
23
+ publish_event TestEvent.new
24
+ end
25
+ end
26
+
27
+ class TestEvent; end
28
+ end
29
+ end
@@ -4,7 +4,7 @@ module Synapse
4
4
  module EventBus
5
5
 
6
6
  class WiringEventListenerTest < Test::Unit::TestCase
7
- def test_notify
7
+ should 'use the correct handler when notified of an events' do
8
8
  listener = ExampleWiringEventListener.new
9
9
 
10
10
  event = Domain::EventMessage.build do |builder|
@@ -4,23 +4,29 @@ module Synapse
4
4
  module EventSourcing
5
5
 
6
6
  class GenericAggregateFactoryTest < Test::Unit::TestCase
7
- def test_create_aggregate
8
- factory = GenericAggregateFactory.new StubAggregate
7
+ def setup
8
+ @factory = GenericAggregateFactory.new StubAggregate
9
+ end
9
10
 
11
+ should 'create an aggregate from a normal event' do
10
12
  event = Domain::DomainEventMessage.build do |m|
11
13
  m.payload = StubCreatedEvent.new 123
12
14
  end
13
15
 
16
+ aggregate = @factory.create_aggregate 123, event
17
+
18
+ assert aggregate.is_a? StubAggregate
19
+ end
20
+
21
+ should 'use an aggregate snapshot if available' do
14
22
  snapshot = StubAggregate.new 123
15
23
  snapshot_event = Domain::DomainEventMessage.build do |m|
16
24
  m.payload = snapshot
17
25
  end
18
26
 
19
- aggregate_a = factory.create_aggregate(123, snapshot_event)
20
- aggregate_b = factory.create_aggregate(123, event)
27
+ aggregate = @factory.create_aggregate 123, snapshot_event
21
28
 
22
- assert aggregate_a.equal? snapshot
23
- assert aggregate_b.is_a? StubAggregate
29
+ assert aggregate.equal? snapshot
24
30
  end
25
31
  end
26
32
 
@@ -5,7 +5,7 @@ module Synapse
5
5
  module EventSourcing
6
6
 
7
7
  class AggregateRootTest < Test::Unit::TestCase
8
- def test_apply
8
+ should 'track published events' do
9
9
  stub = StubAggregate.new 123
10
10
  stub.change_something
11
11
  stub.change_something
@@ -20,7 +20,7 @@ module Synapse
20
20
  assert_equal 2, stub.version
21
21
  end
22
22
 
23
- def test_new_from_stream
23
+ should 'support initializing state from an event stream' do
24
24
  events = Array.new
25
25
  events.push create_event(123, 0, StubCreatedEvent.new(123))
26
26
  events.push create_event(123, 1, StubChangedEvent.new)
@@ -34,7 +34,7 @@ module Synapse
34
34
  assert_equal 2, aggregate.version
35
35
  end
36
36
 
37
- def test_initialize_fails_after_initialization
37
+ should 'raise an exception if initialization is attempted when the aggregate has state' do
38
38
  aggregate = StubAggregate.new 123
39
39
 
40
40
  assert_raise RuntimeError do
@@ -42,7 +42,7 @@ module Synapse
42
42
  end
43
43
  end
44
44
 
45
- def test_child_entities
45
+ should 'notify child entities of aggregate events' do
46
46
  stub_entity_a = StubEntity.new
47
47
  stub_entity_b = StubEntity.new
48
48
 
@@ -5,27 +5,28 @@ module Synapse
5
5
  module EventSourcing
6
6
 
7
7
  class EntityTest < Test::Unit::TestCase
8
- def test_aggregate_root
8
+ should 'raise an exception if an event is published and aggregate root is not set' do
9
9
  entity = StubEntity.new
10
- aggregate_a = StubAggregate.new 123
11
- aggregate_b = StubAggregate.new 123
12
10
 
13
11
  assert_raise RuntimeError do
14
12
  entity.change_something
15
13
  end
16
14
 
17
- entity.aggregate_root = aggregate_a
15
+ aggregate = StubAggregate.new 123
18
16
 
19
- assert_raise RuntimeError do
20
- entity.aggregate_root = aggregate_b
21
- end
17
+ entity.aggregate_root = aggregate
18
+ entity.change_something
22
19
  end
23
20
 
24
- def test_apply
21
+ should 'raise an exception if registration is attempted with more than one aggregate' do
25
22
  entity = StubEntity.new
23
+ aggregate_a = StubAggregate.new 123
24
+ aggregate_b = StubAggregate.new 123
25
+
26
+ entity.aggregate_root = aggregate_a
26
27
 
27
28
  assert_raise RuntimeError do
28
- entity.change_something
29
+ entity.aggregate_root = aggregate_b
29
30
  end
30
31
  end
31
32
  end
@@ -17,7 +17,7 @@ module Synapse
17
17
  @repository.unit_provider = @unit_provider
18
18
  end
19
19
 
20
- def test_add_compatibility
20
+ should 'raise an exception if an incompatible aggregate is added' do
21
21
  aggregate = Domain::Person.new 123, 'Polandball'
22
22
 
23
23
  assert_raise ArgumentError do
@@ -25,7 +25,7 @@ module Synapse
25
25
  end
26
26
  end
27
27
 
28
- def test_load
28
+ should 'load an aggregate from an event stream' do
29
29
  event = create_event(123, 0, StubCreatedEvent.new(123))
30
30
 
31
31
  mock(@event_store).read_events(@factory.type_identifier, 123) do
@@ -35,7 +35,7 @@ module Synapse
35
35
  aggregate = @repository.load 123
36
36
  end
37
37
 
38
- def test_load_incorrect_version
38
+ should 'raise an exception if an unexpected aggregate version is loaded' do
39
39
  event = create_event(123, 1, StubCreatedEvent.new(123))
40
40
 
41
41
  mock(@event_store).read_events(@factory.type_identifier, 123) do
@@ -47,7 +47,7 @@ module Synapse
47
47
  end
48
48
  end
49
49
 
50
- def test_load_not_found
50
+ should 'raise an exception if an event stream could not be found for the aggregate id' do
51
51
  mock(@event_store).read_events(@factory.type_identifier, 123) do
52
52
  raise EventStore::StreamNotFoundError.new @factory.type_identifier, 123
53
53
  end
@@ -57,7 +57,7 @@ module Synapse
57
57
  end
58
58
  end
59
59
 
60
- def test_load_deleted
60
+ should 'raise an exception if the loaded aggregate has been marked for deletion' do
61
61
  event_a = create_event(123, 0, StubCreatedEvent.new(123))
62
62
  event_b = create_event(123, 1, StubDeletedEvent.new)
63
63
 
@@ -70,7 +70,7 @@ module Synapse
70
70
  end
71
71
  end
72
72
 
73
- def test_conflict_resolution
73
+ should 'defer version checking to a conflict resolver if one is set' do
74
74
  @repository.conflict_resolver = ConflictResolver.new
75
75
 
76
76
  event_a = create_event(123, 0, StubCreatedEvent.new(123))
@@ -4,7 +4,7 @@ module Synapse
4
4
  module EventSourcing
5
5
 
6
6
  class EventSourcedStorageListenerTest < Test::Unit::TestCase
7
- def test_store
7
+ should 'append uncommitted aggregate events to the event store' do
8
8
  event_store = Object.new
9
9
  lock_manager = Repository::NullLockManager.new
10
10
  decorators = Array.new
@@ -33,9 +33,9 @@ module Synapse
33
33
  listener.store aggregate
34
34
  end
35
35
 
36
- def test_store_locking
36
+ should 'validate lock if the aggregate is not new' do
37
37
  event_store = Object.new
38
- lock_manager = Repository::NullLockManager.new
38
+ lock_manager = Object.new
39
39
  decorators = Array.new
40
40
  type_identifier = StubAggregate.to_s.demodulize
41
41
  aggregate = StubAggregate.new 123
@@ -44,13 +44,17 @@ module Synapse
44
44
  123
45
45
  end
46
46
 
47
+ mock(lock_manager).validate_lock(aggregate) do
48
+ true
49
+ end
50
+
47
51
  mock(event_store).append_events(type_identifier, anything)
48
52
 
49
53
  listener = EventSourcedStorageListener.new event_store, lock_manager, decorators, type_identifier
50
54
  listener.store aggregate
51
55
  end
52
56
 
53
- def test_store_lock_failed
57
+ should 'raise an exception if the aggregate is not new and the lock is invalid' do
54
58
  event_store = Object.new
55
59
  lock_manager = Object.new
56
60
  decorators = Array.new
@@ -8,13 +8,13 @@ module Synapse
8
8
  @event_store = InMemoryEventStore.new
9
9
  end
10
10
 
11
- def test_empty_stream
11
+ should 'raise an exception if a stream could not be found' do
12
12
  assert_raise StreamNotFoundError do
13
13
  @event_store.read_events 'Person', 123
14
14
  end
15
15
  end
16
16
 
17
- def test_append_and_read
17
+ should 'support appending and reading an event stream' do
18
18
  event_a = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
19
19
  event_b = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
20
20
  event_c = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
@@ -30,7 +30,7 @@ module Synapse
30
30
  assert_equal [event_a, event_b, event_c], stream.to_a
31
31
  end
32
32
 
33
- def test_clear
33
+ should 'be able to be cleared of all streams' do
34
34
  event = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
35
35
  stream = Domain::SimpleDomainEventStream.new event
36
36
 
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module ProcessManager
5
+
6
+ class ContainerResourceInjectorTest < Test::Unit::TestCase
7
+ should 'use a service container to inject resources' do
8
+ container = Object.new
9
+ resource_injector = ContainerResourceInjector.new container
10
+ process = Process.new
11
+
12
+ mock(container).inject_into(process)
13
+
14
+ resource_injector.inject_resources process
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -4,7 +4,7 @@ module Synapse
4
4
  module ProcessManager
5
5
  class CorrelationSetTest < Test::Unit::TestCase
6
6
 
7
- def test_add
7
+ should 'track correlation additions' do
8
8
  correlation = Correlation.new :order_id, '512d5467-d319-481e-ab5e-4d6f7445bcff'
9
9
 
10
10
  set = CorrelationSet.new
@@ -25,7 +25,7 @@ module Synapse
25
25
  assert_equal 0, set.deletions.count
26
26
  end
27
27
 
28
- def test_delete
28
+ should 'track correlation deletions' do
29
29
  correlation = Correlation.new :order_id, '512d5467-d319-481e-ab5e-4d6f7445bcff'
30
30
 
31
31
  set = CorrelationSet.new
@@ -3,14 +3,14 @@ require 'test_helper'
3
3
  module Synapse
4
4
  module ProcessManager
5
5
  class CorrelationTest < Test::Unit::TestCase
6
- def test_intiialize
6
+ should 'coerce key and value to correct types' do
7
7
  correlation = Correlation.new :foo, 'bar'
8
8
 
9
9
  assert_equal :foo, correlation.key
10
10
  assert_equal 'bar', correlation.value
11
11
  end
12
12
 
13
- def test_object_equality
13
+ should 'be able to determine equality with similar correlations' do
14
14
  correlation_a = Correlation.new :foo, 'bar'
15
15
  correlation_b = Correlation.new :foo, 'bar'
16
16
  correlation_c = Correlation.new :foo, 'baz'