synapse-core 0.5.6 → 0.6.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 +7 -0
- data/lib/synapse-core.rb +31 -1
- data/lib/synapse/command.rb +1 -0
- data/lib/synapse/command/callbacks/future.rb +3 -3
- data/lib/synapse/command/callbacks/void.rb +14 -0
- data/lib/synapse/command/command_bus.rb +2 -2
- data/lib/synapse/command/command_callback.rb +9 -2
- data/lib/synapse/command/gateway.rb +1 -1
- data/lib/synapse/command/gateway/interval_retry_scheduler.rb +6 -6
- data/lib/synapse/command/gateway/retry_scheduler.rb +7 -4
- data/lib/synapse/command/interceptor_chain.rb +1 -1
- data/lib/synapse/command/interceptors/serialization.rb +2 -1
- data/lib/synapse/command/simple_command_bus.rb +23 -34
- data/lib/synapse/common.rb +2 -2
- data/lib/synapse/common/concurrency/disposable_lock.rb +157 -0
- data/lib/synapse/common/concurrency/identifier_lock_manager.rb +164 -0
- data/lib/synapse/common/duplication.rb +4 -4
- data/lib/synapse/common/errors.rb +5 -0
- data/lib/synapse/configuration/container.rb +1 -1
- data/lib/synapse/configuration/container_builder.rb +1 -1
- data/lib/synapse/configuration/definition.rb +1 -1
- data/lib/synapse/domain/aggregate_root.rb +1 -1
- data/lib/synapse/domain/simple_stream.rb +3 -5
- data/lib/synapse/domain/stream.rb +2 -2
- data/lib/synapse/event_bus/event_bus.rb +2 -2
- data/lib/synapse/event_bus/simple_event_bus.rb +5 -6
- data/lib/synapse/event_sourcing/caching.rb +1 -1
- data/lib/synapse/event_sourcing/entity.rb +4 -2
- data/lib/synapse/event_sourcing/repository.rb +9 -13
- data/lib/synapse/event_sourcing/snapshot/taker.rb +1 -1
- data/lib/synapse/mapping/mapping.rb +1 -1
- data/lib/synapse/process_manager/correlation.rb +3 -29
- data/lib/synapse/process_manager/pessimistic_lock_manager.rb +3 -3
- data/lib/synapse/process_manager/process.rb +2 -6
- data/lib/synapse/process_manager/process_manager.rb +1 -1
- data/lib/synapse/process_manager/process_repository.rb +1 -1
- data/lib/synapse/process_manager/repository/in_memory.rb +5 -4
- data/lib/synapse/process_manager/simple_process_manager.rb +2 -2
- data/lib/synapse/repository/errors.rb +2 -2
- data/lib/synapse/repository/locking.rb +48 -0
- data/lib/synapse/repository/optimistic_lock_manager.rb +10 -9
- data/lib/synapse/repository/pessimistic_lock_manager.rb +5 -4
- data/lib/synapse/repository/repository.rb +1 -1
- data/lib/synapse/repository/simple_repository.rb +8 -7
- data/lib/synapse/serialization/converter.rb +3 -0
- data/lib/synapse/serialization/converter_factory.rb +6 -5
- data/lib/synapse/serialization/serialized_object.rb +4 -4
- data/lib/synapse/serialization/serialized_type.rb +4 -4
- data/lib/synapse/uow/listener_collection.rb +12 -9
- data/lib/synapse/uow/provider.rb +1 -1
- data/lib/synapse/uow/uow.rb +1 -1
- data/lib/synapse/upcasting/upcaster_chain.rb +1 -1
- data/lib/synapse/version.rb +1 -1
- data/test/command/serialization_test.rb +5 -2
- data/test/command/simple_command_bus_test.rb +9 -16
- data/test/command/validation_test.rb +1 -1
- data/test/common/concurrency/identifier_lock_manager_test.rb +137 -0
- data/test/configuration/component/serialization/converter_factory_test.rb +2 -2
- data/test/event_sourcing/repository_test.rb +18 -0
- data/test/repository/simple_repository_test.rb +42 -10
- data/test/test_helper.rb +3 -4
- metadata +25 -29
- data/lib/synapse.rb +0 -34
- data/lib/synapse/common/concurrency/identifier_lock.rb +0 -56
- data/lib/synapse/common/concurrency/public_lock.rb +0 -95
- data/lib/synapse/event_bus/clustering/cluster.rb +0 -10
- data/lib/synapse/event_bus/clustering/event_bus.rb +0 -55
- data/lib/synapse/event_bus/clustering/selector.rb +0 -14
- data/lib/synapse/rails/injection_helper.rb +0 -23
- data/lib/synapse/railtie.rb +0 -17
- data/test/common/concurrency/identifier_lock_test.rb +0 -25
- data/test/common/concurrency/public_lock_test.rb +0 -83
- data/test/process_manager/correlation_test.rb +0 -24
- data/test/rails/injection_helper_test.rb +0 -27
@@ -1,14 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module EventBus
|
3
|
-
# Represents a mechanism for assigning event listeners to clusters
|
4
|
-
# @abstract
|
5
|
-
class ClusterSelector
|
6
|
-
# Selects and returns a suitable cluster for the given event listener
|
7
|
-
#
|
8
|
-
# @abstract
|
9
|
-
# @param [EventListener] listener
|
10
|
-
# @return [Cluster] Returns nil if no suitable cluster
|
11
|
-
def select_cluster(listener); end
|
12
|
-
end # ClusterSelector
|
13
|
-
end # EventBus
|
14
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Rails
|
3
|
-
# Mixin for an action controller in Rails that adds dependency injection
|
4
|
-
module InjectionHelper
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
before_filter :inject_dependencies
|
9
|
-
end
|
10
|
-
|
11
|
-
# Performs one-time dependency injection before an action is called
|
12
|
-
# @return [undefined]
|
13
|
-
def inject_dependencies
|
14
|
-
return if @_dependencies_injected
|
15
|
-
|
16
|
-
container = Synapse.container
|
17
|
-
container.inject_into self
|
18
|
-
|
19
|
-
@_dependencies_injected = true
|
20
|
-
end
|
21
|
-
end # InjectionHelper
|
22
|
-
end # Rails
|
23
|
-
end
|
data/lib/synapse/railtie.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
# Simple integration between the Synapse framework and Rails 3.2+
|
3
|
-
class Railtie < Rails::Railtie
|
4
|
-
# Set the name of the Railtie
|
5
|
-
railtie_name :synapse
|
6
|
-
|
7
|
-
# Controllers will get dependencies injected automatically
|
8
|
-
initializer 'synapse.include_controller_mixins' do
|
9
|
-
ActionController::Base.class_eval do
|
10
|
-
include Synapse::Configuration::Dependent
|
11
|
-
include Synapse::Rails::InjectionHelper
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end # Railtie
|
15
|
-
end
|
16
|
-
|
17
|
-
require 'synapse/rails/injection_helper'
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Synapse
|
4
|
-
class IdentifierLockTest < Test::Unit::TestCase
|
5
|
-
should 'indicate whether the current thread holds a lock' do
|
6
|
-
lock = IdentifierLock.new
|
7
|
-
identifier = 'some_id'
|
8
|
-
|
9
|
-
refute lock.owned? identifier
|
10
|
-
|
11
|
-
lock.obtain_lock identifier
|
12
|
-
assert lock.owned? identifier
|
13
|
-
|
14
|
-
lock.release_lock identifier
|
15
|
-
refute lock.owned? identifier
|
16
|
-
end
|
17
|
-
|
18
|
-
should 'raise an exception when a thread releases a lock it does not own' do
|
19
|
-
lock = IdentifierLock.new
|
20
|
-
assert_raise ThreadError do
|
21
|
-
lock.release_lock 'derp'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Synapse
|
4
|
-
class PublicLockTest < Test::Unit::TestCase
|
5
|
-
should 'raise an exception when a thread tries to obtain a lock twice' do
|
6
|
-
@lock = PublicLock.new
|
7
|
-
@lock.lock
|
8
|
-
|
9
|
-
assert_raise ThreadError do
|
10
|
-
@lock.lock
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'properly manage its list of waiting threads' do
|
15
|
-
@lock = PublicLock.new
|
16
|
-
@lock.lock
|
17
|
-
|
18
|
-
t = Thread.new do
|
19
|
-
@lock.lock
|
20
|
-
end
|
21
|
-
|
22
|
-
wait_until do
|
23
|
-
@lock.waiting == [t]
|
24
|
-
end
|
25
|
-
|
26
|
-
t.kill
|
27
|
-
|
28
|
-
wait_until do
|
29
|
-
@lock.waiting == []
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
should 'synchronize the execution of a block' do
|
34
|
-
@lock = PublicLock.new
|
35
|
-
|
36
|
-
refute @lock.owned?
|
37
|
-
refute @lock.owned_by? Thread.current
|
38
|
-
|
39
|
-
@lock.synchronize do
|
40
|
-
assert @lock.owned?
|
41
|
-
assert @lock.owned_by? Thread.current
|
42
|
-
end
|
43
|
-
|
44
|
-
refute @lock.owned?
|
45
|
-
refute @lock.owned_by? Thread.current
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'raise an exception when a thread releases a lock it does not own' do
|
49
|
-
@lock = PublicLock.new
|
50
|
-
|
51
|
-
assert_raise ThreadError do
|
52
|
-
@lock.unlock
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
should 'provide a non-blocking lock attempt' do
|
57
|
-
@lock = PublicLock.new
|
58
|
-
|
59
|
-
t = Thread.new do
|
60
|
-
assert @lock.try_lock
|
61
|
-
Thread.stop
|
62
|
-
@lock.unlock
|
63
|
-
end
|
64
|
-
|
65
|
-
wait_until do
|
66
|
-
@lock.owned_by? t
|
67
|
-
end
|
68
|
-
|
69
|
-
refute @lock.try_lock
|
70
|
-
|
71
|
-
t.wakeup
|
72
|
-
end
|
73
|
-
|
74
|
-
should 'raise an exception when a thread tries to obtain a non-blocking lock twice' do
|
75
|
-
@lock = PublicLock.new
|
76
|
-
@lock.try_lock
|
77
|
-
|
78
|
-
assert_raise ThreadError do
|
79
|
-
@lock.try_lock
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Synapse
|
4
|
-
module ProcessManager
|
5
|
-
class CorrelationTest < Test::Unit::TestCase
|
6
|
-
should 'coerce key and value to correct types' do
|
7
|
-
correlation = Correlation.new :foo, 'bar'
|
8
|
-
|
9
|
-
assert_equal :foo, correlation.key
|
10
|
-
assert_equal 'bar', correlation.value
|
11
|
-
end
|
12
|
-
|
13
|
-
should 'be able to determine equality with similar correlations' do
|
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
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'rails'
|
4
|
-
require 'synapse/railtie'
|
5
|
-
|
6
|
-
module Synapse
|
7
|
-
module Rails
|
8
|
-
class InjectionHelperTest < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@controller_class = Class.new
|
12
|
-
@controller = @controller_class.new
|
13
|
-
mock(@controller_class).before_filter(:inject_dependencies)
|
14
|
-
@controller_class.send :include, InjectionHelper
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'inject dependencies only once' do
|
18
|
-
container_mock = mock(Synapse).container.mock!
|
19
|
-
container_mock.inject_into(@controller)
|
20
|
-
|
21
|
-
@controller.inject_dependencies
|
22
|
-
@controller.inject_dependencies
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|