synapse-core 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/lib/synapse.rb +351 -0
  2. data/lib/synapse/command/command_bus.rb +45 -0
  3. data/lib/synapse/command/command_callback.rb +18 -0
  4. data/lib/synapse/command/command_filter.rb +17 -0
  5. data/lib/synapse/command/command_handler.rb +13 -0
  6. data/lib/synapse/command/dispatch_interceptor.rb +16 -0
  7. data/lib/synapse/command/duplication.rb +43 -0
  8. data/lib/synapse/command/errors.rb +27 -0
  9. data/lib/synapse/command/filters/validation.rb +32 -0
  10. data/lib/synapse/command/gateway.rb +34 -0
  11. data/lib/synapse/command/interceptor_chain.rb +31 -0
  12. data/lib/synapse/command/interceptors/serialization.rb +35 -0
  13. data/lib/synapse/command/message.rb +19 -0
  14. data/lib/synapse/command/rollback_policy.rb +22 -0
  15. data/lib/synapse/command/simple_command_bus.rb +138 -0
  16. data/lib/synapse/command/wiring.rb +47 -0
  17. data/lib/synapse/domain/aggregate_root.rb +121 -0
  18. data/lib/synapse/domain/event_container.rb +127 -0
  19. data/lib/synapse/domain/message.rb +82 -0
  20. data/lib/synapse/domain/message_builder.rb +34 -0
  21. data/lib/synapse/domain/stream.rb +108 -0
  22. data/lib/synapse/duplication.rb +60 -0
  23. data/lib/synapse/errors.rb +13 -0
  24. data/lib/synapse/event_bus/event_bus.rb +40 -0
  25. data/lib/synapse/event_bus/event_listener.rb +16 -0
  26. data/lib/synapse/event_bus/event_listener_proxy.rb +12 -0
  27. data/lib/synapse/event_bus/simple_event_bus.rb +69 -0
  28. data/lib/synapse/event_bus/wiring.rb +23 -0
  29. data/lib/synapse/event_sourcing/aggregate_factory.rb +69 -0
  30. data/lib/synapse/event_sourcing/aggregate_root.rb +104 -0
  31. data/lib/synapse/event_sourcing/conflict_resolver.rb +80 -0
  32. data/lib/synapse/event_sourcing/entity.rb +64 -0
  33. data/lib/synapse/event_sourcing/member.rb +72 -0
  34. data/lib/synapse/event_sourcing/repository.rb +119 -0
  35. data/lib/synapse/event_sourcing/snapshot/count_stream.rb +86 -0
  36. data/lib/synapse/event_sourcing/snapshot/count_trigger.rb +91 -0
  37. data/lib/synapse/event_sourcing/snapshot/taker.rb +73 -0
  38. data/lib/synapse/event_sourcing/storage_listener.rb +34 -0
  39. data/lib/synapse/event_sourcing/stream_decorator.rb +25 -0
  40. data/lib/synapse/event_store/errors.rb +16 -0
  41. data/lib/synapse/event_store/event_store.rb +43 -0
  42. data/lib/synapse/event_store/in_memory.rb +59 -0
  43. data/lib/synapse/event_store/mongo/cursor_event_stream.rb +63 -0
  44. data/lib/synapse/event_store/mongo/event_store.rb +86 -0
  45. data/lib/synapse/event_store/mongo/per_commit_strategy.rb +253 -0
  46. data/lib/synapse/event_store/mongo/per_event_strategy.rb +143 -0
  47. data/lib/synapse/event_store/mongo/storage_strategy.rb +113 -0
  48. data/lib/synapse/event_store/mongo/template.rb +73 -0
  49. data/lib/synapse/identifier.rb +23 -0
  50. data/lib/synapse/message.rb +101 -0
  51. data/lib/synapse/message_builder.rb +38 -0
  52. data/lib/synapse/process_manager/correlation.rb +32 -0
  53. data/lib/synapse/process_manager/correlation_resolver.rb +14 -0
  54. data/lib/synapse/process_manager/correlation_set.rb +58 -0
  55. data/lib/synapse/process_manager/process.rb +71 -0
  56. data/lib/synapse/repository/errors.rb +26 -0
  57. data/lib/synapse/repository/lock_manager.rb +40 -0
  58. data/lib/synapse/repository/locking.rb +97 -0
  59. data/lib/synapse/repository/pessimistic_lock_manager.rb +61 -0
  60. data/lib/synapse/repository/repository.rb +109 -0
  61. data/lib/synapse/serialization/converter.rb +39 -0
  62. data/lib/synapse/serialization/converter/chain.rb +45 -0
  63. data/lib/synapse/serialization/converter/factory.rb +68 -0
  64. data/lib/synapse/serialization/converter/identity.rb +29 -0
  65. data/lib/synapse/serialization/converter/json.rb +31 -0
  66. data/lib/synapse/serialization/converter/ox.rb +31 -0
  67. data/lib/synapse/serialization/errors.rb +12 -0
  68. data/lib/synapse/serialization/lazy_object.rb +61 -0
  69. data/lib/synapse/serialization/message/data.rb +25 -0
  70. data/lib/synapse/serialization/message/metadata.rb +13 -0
  71. data/lib/synapse/serialization/message/serialization_aware.rb +17 -0
  72. data/lib/synapse/serialization/message/serialization_aware_message.rb +66 -0
  73. data/lib/synapse/serialization/message/serialized_message.rb +201 -0
  74. data/lib/synapse/serialization/message/serialized_message_builder.rb +64 -0
  75. data/lib/synapse/serialization/message/serialized_object_cache.rb +50 -0
  76. data/lib/synapse/serialization/message/serializer.rb +47 -0
  77. data/lib/synapse/serialization/revision_resolver.rb +30 -0
  78. data/lib/synapse/serialization/serialized_object.rb +37 -0
  79. data/lib/synapse/serialization/serialized_type.rb +31 -0
  80. data/lib/synapse/serialization/serializer.rb +98 -0
  81. data/lib/synapse/serialization/serializer/marshal.rb +32 -0
  82. data/lib/synapse/serialization/serializer/oj.rb +34 -0
  83. data/lib/synapse/serialization/serializer/ox.rb +31 -0
  84. data/lib/synapse/uow/factory.rb +28 -0
  85. data/lib/synapse/uow/listener.rb +79 -0
  86. data/lib/synapse/uow/listener_collection.rb +93 -0
  87. data/lib/synapse/uow/nesting.rb +262 -0
  88. data/lib/synapse/uow/provider.rb +71 -0
  89. data/lib/synapse/uow/storage_listener.rb +14 -0
  90. data/lib/synapse/uow/transaction_manager.rb +27 -0
  91. data/lib/synapse/uow/uow.rb +178 -0
  92. data/lib/synapse/upcasting/chain.rb +78 -0
  93. data/lib/synapse/upcasting/context.rb +58 -0
  94. data/lib/synapse/upcasting/data.rb +30 -0
  95. data/lib/synapse/upcasting/single_upcaster.rb +57 -0
  96. data/lib/synapse/upcasting/upcaster.rb +55 -0
  97. data/lib/synapse/version.rb +3 -0
  98. data/lib/synapse/wiring/message_wiring.rb +41 -0
  99. data/lib/synapse/wiring/wire.rb +55 -0
  100. data/lib/synapse/wiring/wire_registry.rb +61 -0
  101. data/test/command/duplication_test.rb +54 -0
  102. data/test/command/gateway_test.rb +25 -0
  103. data/test/command/interceptor_chain_test.rb +26 -0
  104. data/test/command/serialization_test.rb +37 -0
  105. data/test/command/simple_command_bus_test.rb +141 -0
  106. data/test/command/validation_test.rb +42 -0
  107. data/test/command/wiring_test.rb +73 -0
  108. data/test/domain/aggregate_root_test.rb +57 -0
  109. data/test/domain/fixtures.rb +31 -0
  110. data/test/domain/message_test.rb +61 -0
  111. data/test/domain/stream_test.rb +35 -0
  112. data/test/duplication_test.rb +40 -0
  113. data/test/event_bus/wiring_test.rb +46 -0
  114. data/test/event_sourcing/aggregate_factory_test.rb +28 -0
  115. data/test/event_sourcing/aggregate_root_test.rb +76 -0
  116. data/test/event_sourcing/entity_test.rb +34 -0
  117. data/test/event_sourcing/fixtures.rb +85 -0
  118. data/test/event_sourcing/repository_test.rb +102 -0
  119. data/test/event_sourcing/snapshot/aggregate_taker_test.rb +39 -0
  120. data/test/event_sourcing/snapshot/deferred_taker_test.rb +19 -0
  121. data/test/event_sourcing/snapshot/integration_test.rb +65 -0
  122. data/test/event_sourcing/storage_listener_test.rb +77 -0
  123. data/test/event_store/in_memory_test.rb +47 -0
  124. data/test/process_manager/correlation_set_test.rb +49 -0
  125. data/test/process_manager/correlation_test.rb +24 -0
  126. data/test/process_manager/process_test.rb +52 -0
  127. data/test/repository/locking_test.rb +101 -0
  128. data/test/serialization/converter/factory_test.rb +33 -0
  129. data/test/serialization/converter/identity_test.rb +17 -0
  130. data/test/serialization/converter/json_test.rb +31 -0
  131. data/test/serialization/converter/ox_test.rb +40 -0
  132. data/test/serialization/fixtures.rb +17 -0
  133. data/test/serialization/lazy_object_test.rb +32 -0
  134. data/test/serialization/message/metadata_test.rb +19 -0
  135. data/test/serialization/message/serialization_aware_message_test.rb +88 -0
  136. data/test/serialization/message/serialized_message_builder_test.rb +41 -0
  137. data/test/serialization/message/serialized_message_test.rb +140 -0
  138. data/test/serialization/message/serializer_test.rb +50 -0
  139. data/test/serialization/revision_resolver_test.rb +12 -0
  140. data/test/serialization/serialized_object_test.rb +36 -0
  141. data/test/serialization/serialized_type_test.rb +27 -0
  142. data/test/serialization/serializer/marshal_test.rb +22 -0
  143. data/test/serialization/serializer/oj_test.rb +24 -0
  144. data/test/serialization/serializer/ox_test.rb +36 -0
  145. data/test/serialization/serializer_test.rb +20 -0
  146. data/test/test_helper.rb +19 -0
  147. data/test/uow/factory_test.rb +23 -0
  148. data/test/uow/outer_commit_listener_test.rb +50 -0
  149. data/test/uow/provider_test.rb +70 -0
  150. data/test/uow/uow_test.rb +337 -0
  151. data/test/upcasting/chain_test.rb +29 -0
  152. data/test/upcasting/fixtures.rb +66 -0
  153. data/test/wiring/wire_registry_test.rb +60 -0
  154. data/test/wiring/wire_test.rb +51 -0
  155. metadata +263 -0
@@ -0,0 +1,102 @@
1
+ require 'test_helper'
2
+ require 'domain/fixtures'
3
+
4
+ module Synapse
5
+ module EventSourcing
6
+ class EventSourcingRepositoryTest < Test::Unit::TestCase
7
+ def setup
8
+ @unit_provider = UnitOfWork::UnitOfWorkProvider.new
9
+ @unit = UnitOfWork::UnitOfWork.new @unit_provider
10
+ @unit.start
11
+ @factory = GenericAggregateFactory.new StubAggregate
12
+ @event_store = Object.new
13
+ @lock_manager = Repository::NullLockManager.new
14
+
15
+ @repository = EventSourcingRepository.new @factory, @event_store, @lock_manager
16
+ @repository.event_bus = EventBus::SimpleEventBus.new
17
+ @repository.unit_provider = @unit_provider
18
+ end
19
+
20
+ def test_add_compatibility
21
+ aggregate = Domain::Person.new 123, 'Polandball'
22
+
23
+ assert_raise ArgumentError do
24
+ @repository.add aggregate # Polandball can't into repository :(
25
+ end
26
+ end
27
+
28
+ def test_load
29
+ event = create_event(123, 0, StubCreatedEvent.new(123))
30
+
31
+ mock(@event_store).read_events(@factory.type_identifier, 123) do
32
+ Domain::SimpleDomainEventStream.new event
33
+ end
34
+
35
+ aggregate = @repository.load 123
36
+ end
37
+
38
+ def test_load_incorrect_version
39
+ event = create_event(123, 1, StubCreatedEvent.new(123))
40
+
41
+ mock(@event_store).read_events(@factory.type_identifier, 123) do
42
+ Domain::SimpleDomainEventStream.new event
43
+ end
44
+
45
+ assert_raise Repository::ConflictingAggregateVersionError do
46
+ aggregate = @repository.load 123, 0
47
+ end
48
+ end
49
+
50
+ def test_load_not_found
51
+ mock(@event_store).read_events(@factory.type_identifier, 123) do
52
+ raise EventStore::StreamNotFoundError.new @factory.type_identifier, 123
53
+ end
54
+
55
+ assert_raise Repository::AggregateNotFoundError do
56
+ @repository.load 123
57
+ end
58
+ end
59
+
60
+ def test_load_deleted
61
+ event_a = create_event(123, 0, StubCreatedEvent.new(123))
62
+ event_b = create_event(123, 1, StubDeletedEvent.new)
63
+
64
+ mock(@event_store).read_events(@factory.type_identifier, 123) do
65
+ Domain::SimpleDomainEventStream.new event_a, event_b
66
+ end
67
+
68
+ assert_raise AggregateDeletedError do
69
+ aggregate = @repository.load 123
70
+ end
71
+ end
72
+
73
+ def test_conflict_resolution
74
+ @repository.conflict_resolver = ConflictResolver.new
75
+
76
+ event_a = create_event(123, 0, StubCreatedEvent.new(123))
77
+ event_b = create_event(123, 1, StubChangedEvent.new)
78
+
79
+ mock(@event_store).read_events(@factory.type_identifier, 123) do
80
+ Domain::SimpleDomainEventStream.new event_a, event_b
81
+ end
82
+
83
+ mock(@event_store).append_events(@factory.type_identifier, anything)
84
+
85
+ aggregate = @repository.load 123, 0
86
+ aggregate.change_something
87
+
88
+ @unit.commit
89
+ end
90
+
91
+ private
92
+
93
+ def create_event(aggregate_id, seq, payload)
94
+ Domain::DomainEventMessage.build do |m|
95
+ m.aggregate_id = aggregate_id
96
+ m.sequence_number = seq
97
+ m.payload = payload
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'event_sourcing/fixtures'
3
+
4
+ module Synapse
5
+ module EventSourcing
6
+
7
+ class AggregateSnapshotTakerTest < Test::Unit::TestCase
8
+ def test_schedule_snapshot
9
+ event_store = Object.new
10
+ aggregate_factory = GenericAggregateFactory.new StubAggregate
11
+
12
+ type_identifier = aggregate_factory.type_identifier
13
+ id = 123
14
+
15
+ event = Domain::DomainEventMessage.build do |builder|
16
+ builder.payload = StubCreatedEvent.new id
17
+ builder.sequence_number = 0
18
+ builder.aggregate_id = id
19
+ end
20
+ stream = Domain::SimpleDomainEventStream.new event
21
+
22
+ mock(event_store).read_events(type_identifier, id) do
23
+ stream
24
+ end
25
+
26
+ mock(event_store).append_snapshot_event(type_identifier, anything) do |_, snapshot|
27
+ assert_equal StubAggregate, snapshot.payload_type
28
+ assert_equal 0, snapshot.sequence_number
29
+ assert_equal id, snapshot.aggregate_id
30
+ end
31
+
32
+ snapshot_taker = AggregateSnapshotTaker.new event_store
33
+ snapshot_taker.register_factory aggregate_factory
34
+ snapshot_taker.schedule_snapshot type_identifier, id
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module EventSourcing
5
+
6
+ class DeferredSnapshotTakerTest < Test::Unit::TestCase
7
+ def test_schedule_snapshot
8
+ delegate = Object.new
9
+
10
+ mock(EventMachine).defer.yields
11
+ mock(delegate).schedule_snapshot 'test', 123
12
+
13
+ snapshot_taker = DeferredSnapshotTaker.new delegate
14
+ snapshot_taker.schedule_snapshot 'test', 123
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+ require 'event_sourcing/fixtures'
3
+
4
+ module Synapse
5
+ module EventSourcing
6
+
7
+ class SnapshotIntegrationTest < Test::Unit::TestCase
8
+ def test_integration
9
+ unit_provider = Object.new
10
+ unit = Object.new
11
+
12
+ mock(unit_provider).current do
13
+ unit
14
+ end
15
+
16
+ listener = nil
17
+
18
+ mock(unit).register_listener(is_a(SnapshotUnitOfWorkListener)) do |l|
19
+ listener = l
20
+ end
21
+
22
+ event_store = Object.new
23
+
24
+ aggregate_id = 123
25
+ type_identifier = Object.to_s
26
+
27
+ aggregate = Object.new
28
+ mock(aggregate).id.any_times do
29
+ aggregate_id
30
+ end
31
+
32
+ snapshot_taker = Object.new
33
+ snapshot_trigger = EventCountSnapshotTrigger.new snapshot_taker, unit_provider
34
+ snapshot_trigger.threshold = 5
35
+
36
+ read_stream = create_stream 3
37
+ append_stream = create_stream 3
38
+
39
+ decorated_read_stream = snapshot_trigger.decorate_for_read type_identifier, aggregate_id, read_stream
40
+ decorated_read_stream.to_a # Causes stream to iterate over all events
41
+
42
+ decorated_append_stream = snapshot_trigger.decorate_for_append type_identifier, aggregate, append_stream
43
+ decorated_append_stream.to_a # Ditto
44
+
45
+ # At this point, there is a snapshot unit of work listener added
46
+ # Let's "cleanup" the unit of work and check if the snapshot is triggered
47
+
48
+ mock(snapshot_taker).schedule_snapshot type_identifier, aggregate_id
49
+
50
+ listener.on_cleanup unit
51
+ end
52
+
53
+ def create_stream(size)
54
+ events = Array.new
55
+
56
+ size.times do
57
+ events.push Domain::DomainEventMessage.build
58
+ end
59
+
60
+ Domain::SimpleDomainEventStream.new events
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module EventSourcing
5
+
6
+ class EventSourcedStorageListenerTest < Test::Unit::TestCase
7
+ def test_store
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
+ def test_store_locking
37
+ event_store = Object.new
38
+ lock_manager = Repository::NullLockManager.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(event_store).append_events(type_identifier, anything)
48
+
49
+ listener = EventSourcedStorageListener.new event_store, lock_manager, decorators, type_identifier
50
+ listener.store aggregate
51
+ end
52
+
53
+ def test_store_lock_failed
54
+ event_store = Object.new
55
+ lock_manager = Object.new
56
+ decorators = Array.new
57
+ type_identifier = StubAggregate.to_s.demodulize
58
+ aggregate = Object.new
59
+
60
+ mock(aggregate).version do
61
+ 123
62
+ end
63
+
64
+ mock(lock_manager).validate_lock(aggregate) do
65
+ false
66
+ end
67
+
68
+ listener = EventSourcedStorageListener.new event_store, lock_manager, decorators, type_identifier
69
+
70
+ assert_raise Repository::ConflictingModificationError do
71
+ listener.store aggregate
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module EventStore
5
+ class InMemoryEventStoreTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @event_store = InMemoryEventStore.new
9
+ end
10
+
11
+ def test_empty_stream
12
+ assert_raise StreamNotFoundError do
13
+ @event_store.read_events 'Person', 123
14
+ end
15
+ end
16
+
17
+ def test_append_and_read
18
+ event_a = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
19
+ event_b = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
20
+ event_c = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
21
+
22
+ stream_a = Domain::SimpleDomainEventStream.new event_a, event_b
23
+ stream_b = Domain::SimpleDomainEventStream.new event_c
24
+
25
+ @event_store.append_events 'Person', stream_a
26
+ @event_store.append_events 'Person', stream_b
27
+
28
+ stream = @event_store.read_events 'Person', 123
29
+
30
+ assert_equal [event_a, event_b, event_c], stream.to_a
31
+ end
32
+
33
+ def test_clear
34
+ event = Domain::DomainEventMessage.build { |e| e.aggregate_id = 123 }
35
+ stream = Domain::SimpleDomainEventStream.new event
36
+
37
+ @event_store.append_events 'Person', stream
38
+ @event_store.clear
39
+
40
+ assert_raise StreamNotFoundError do
41
+ @event_store.read_events 'Person', 123
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module ProcessManager
5
+ class CorrelationSetTest < Test::Unit::TestCase
6
+
7
+ def test_add
8
+ correlation = Correlation.new :order_id, '512d5467-d319-481e-ab5e-4d6f7445bcff'
9
+
10
+ set = CorrelationSet.new
11
+ set.add correlation
12
+ set.add correlation
13
+
14
+ assert set.include? correlation
15
+ assert_equal 1, set.count
16
+ assert_equal 1, set.additions.count
17
+
18
+ set.commit
19
+
20
+ set.delete correlation
21
+ set.add correlation
22
+
23
+ assert_equal 1, set.count
24
+ assert_equal 0, set.additions.count
25
+ assert_equal 0, set.deletions.count
26
+ end
27
+
28
+ def test_delete
29
+ correlation = Correlation.new :order_id, '512d5467-d319-481e-ab5e-4d6f7445bcff'
30
+
31
+ set = CorrelationSet.new
32
+ set.add correlation
33
+ set.delete correlation
34
+
35
+ assert_equal 0, set.count
36
+ assert_equal 0, set.additions.count
37
+ assert_equal 0, set.deletions.count
38
+
39
+ set.add correlation
40
+ set.commit
41
+
42
+ set.delete correlation
43
+ assert_equal 0, set.count
44
+ assert_equal 1, set.deletions.count
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module ProcessManager
5
+ class CorrelationTest < Test::Unit::TestCase
6
+ def test_intiialize
7
+ correlation = Correlation.new :foo, 'bar'
8
+
9
+ assert_equal :foo, correlation.key
10
+ assert_equal 'bar', correlation.value
11
+ end
12
+
13
+ def test_object_equality
14
+ correlation_a = Correlation.new :foo, 'bar'
15
+ correlation_b = Correlation.new :foo, 'bar'
16
+ correlation_c = Correlation.new :foo, 'baz'
17
+
18
+ assert_equal correlation_a, correlation_b
19
+ assert_equal correlation_b, correlation_b
20
+ refute_equal correlation_a, correlation_c
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ module Synapse
4
+ module ProcessManager
5
+
6
+ class ProcessTest < Test::Unit::TestCase
7
+ def test_initialize
8
+ process = StubProcess.new
9
+ correlation = Correlation.new :process_id, process.id
10
+
11
+ # If no identifier was given, one should be generated
12
+ refute process.id.nil?
13
+ assert process.correlations.include? correlation
14
+ assert process.active?
15
+ end
16
+
17
+ def test_dissociate_from
18
+ process = StubProcess.new
19
+
20
+ key = :order_id
21
+ value = '512d5467'
22
+
23
+ process.cause_correlate key, value
24
+ assert process.correlations.include? Correlation.new(key, value)
25
+
26
+ process.cause_dissociate key, value
27
+ refute process.correlations.include? Correlation.new(key, value)
28
+ end
29
+
30
+ def test_finish
31
+ process = StubProcess.new
32
+ process.cause_finish
33
+
34
+ refute process.active?
35
+ end
36
+ end
37
+
38
+ class StubProcess < Process
39
+ def cause_finish
40
+ finish
41
+ end
42
+
43
+ def cause_correlate(key, value)
44
+ correlate_with key, value
45
+ end
46
+ def cause_dissociate(key, value)
47
+ dissociate_from key, value
48
+ end
49
+ end
50
+
51
+ end
52
+ end