synapse-core 0.4.0 → 0.5.1
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.
- data/lib/synapse/command/async_command_bus.rb +41 -0
- data/lib/synapse/command/command_callback.rb +49 -2
- data/lib/synapse/command/command_handler.rb +2 -0
- data/lib/synapse/command/filters/validation.rb +2 -2
- data/lib/synapse/command/gateway/interval_retry_scheduler.rb +75 -0
- data/lib/synapse/command/gateway/retry_scheduler.rb +26 -0
- data/lib/synapse/command/gateway/retrying_callback.rb +46 -0
- data/lib/synapse/command/gateway.rb +56 -11
- data/lib/synapse/command/interceptor_chain.rb +2 -2
- data/lib/synapse/command/interceptors/serialization.rb +2 -2
- data/lib/synapse/command/message.rb +16 -0
- data/lib/synapse/command/simple_command_bus.rb +6 -2
- data/lib/synapse/command/wiring.rb +3 -3
- data/lib/synapse/command.rb +7 -1
- data/lib/synapse/common/concurrency/identifier_lock.rb +2 -17
- data/lib/synapse/common/concurrency/public_lock.rb +8 -9
- data/lib/synapse/common/errors.rb +1 -1
- data/lib/synapse/common/message.rb +2 -6
- data/lib/synapse/common.rb +9 -0
- data/lib/synapse/configuration/component/command_bus/async_command_bus.rb +41 -0
- data/lib/synapse/configuration/component/command_bus/gateway.rb +38 -0
- data/lib/synapse/configuration/component/command_bus/simple_command_bus.rb +81 -0
- data/lib/synapse/configuration/component/command_bus.rb +35 -0
- data/lib/synapse/configuration/component/event_bus/simple_event_bus.rb +41 -0
- data/lib/synapse/configuration/component/event_bus.rb +15 -0
- data/lib/synapse/configuration/component/event_sourcing/repository.rb +62 -0
- data/lib/synapse/configuration/component/event_sourcing.rb +15 -0
- data/lib/synapse/configuration/component/repository/locking_repository.rb +85 -0
- data/lib/synapse/configuration/component/repository/simple_repository.rb +31 -0
- data/lib/synapse/configuration/component/repository.rb +15 -0
- data/lib/synapse/configuration/component/serialization/converter_factory.rb +50 -0
- data/lib/synapse/configuration/component/serialization/serializer.rb +90 -0
- data/lib/synapse/configuration/component/serialization.rb +25 -0
- data/lib/synapse/configuration/component/uow/unit_factory.rb +51 -0
- data/lib/synapse/configuration/component/uow.rb +22 -0
- data/lib/synapse/configuration/component/upcasting/upcaster_chain.rb +61 -0
- data/lib/synapse/configuration/component/upcasting.rb +15 -0
- data/lib/synapse/configuration/container.rb +80 -0
- data/lib/synapse/configuration/container_builder.rb +108 -0
- data/lib/synapse/configuration/definition.rb +31 -0
- data/lib/synapse/configuration/definition_builder.rb +138 -0
- data/lib/synapse/configuration/dependent.rb +31 -0
- data/lib/synapse/configuration/ext.rb +35 -0
- data/lib/synapse/configuration.rb +32 -0
- data/lib/synapse/domain/aggregate_root.rb +25 -26
- data/lib/synapse/domain/event_container.rb +5 -5
- data/lib/synapse/domain/message.rb +16 -0
- data/lib/synapse/event_bus/event_listener.rb +2 -0
- data/lib/synapse/event_bus/event_publisher.rb +19 -0
- data/lib/synapse/event_bus/simple_event_bus.rb +21 -30
- data/lib/synapse/event_bus/wiring.rb +5 -4
- data/lib/synapse/event_bus.rb +1 -1
- data/lib/synapse/event_sourcing/aggregate_root.rb +6 -4
- data/lib/synapse/process_manager/container_resource_injector.rb +18 -0
- data/lib/synapse/process_manager/pessimistic_lock_manager.rb +1 -1
- data/lib/synapse/process_manager/process.rb +4 -0
- data/lib/synapse/process_manager/process_factory.rb +3 -3
- data/lib/synapse/process_manager/repository/in_memory.rb +1 -1
- data/lib/synapse/process_manager/wiring/process.rb +6 -6
- data/lib/synapse/process_manager/wiring/process_manager.rb +8 -8
- data/lib/synapse/process_manager.rb +2 -0
- data/lib/synapse/repository/locking.rb +5 -3
- data/lib/synapse/repository/optimistic_lock_manager.rb +2 -7
- data/lib/synapse/repository/pessimistic_lock_manager.rb +3 -3
- data/lib/synapse/repository/repository.rb +2 -2
- data/lib/synapse/repository/simple_repository.rb +69 -0
- data/lib/synapse/repository.rb +1 -0
- data/lib/synapse/serialization/converter/chain.rb +2 -2
- data/lib/synapse/serialization/converter_factory.rb +2 -2
- data/lib/synapse/serialization/lazy_object.rb +2 -2
- data/lib/synapse/serialization/message/serialization_aware_message.rb +3 -3
- data/lib/synapse/serialization/message/serialized_message.rb +6 -10
- data/lib/synapse/serialization/message/serialized_message_builder.rb +4 -4
- data/lib/synapse/serialization/message/serialized_object_cache.rb +2 -2
- data/lib/synapse/serialization/message/serializer.rb +2 -2
- data/lib/synapse/serialization/revision_resolver.rb +3 -3
- data/lib/synapse/serialization/serialized_object.rb +2 -2
- data/lib/synapse/serialization/serialized_type.rb +2 -2
- data/lib/synapse/serialization/serializer/attribute.rb +2 -2
- data/lib/synapse/serialization/serializer/marshal.rb +2 -2
- data/lib/synapse/serialization/serializer/oj.rb +2 -2
- data/lib/synapse/serialization/serializer/ox.rb +2 -2
- data/lib/synapse/serialization/serializer.rb +2 -2
- data/lib/synapse/uow/factory.rb +2 -2
- data/lib/synapse/uow/listener_collection.rb +2 -2
- data/lib/synapse/uow/nesting.rb +9 -2
- data/lib/synapse/uow/provider.rb +2 -2
- data/lib/synapse/uow/uow.rb +8 -2
- data/lib/synapse/upcasting/{chain.rb → upcaster_chain.rb} +0 -0
- data/lib/synapse/upcasting.rb +1 -1
- data/lib/synapse/version.rb +1 -1
- data/lib/synapse/wiring/message_wiring.rb +31 -0
- data/lib/synapse.rb +2 -14
- data/test/auditing/data_provider_test.rb +2 -2
- data/test/auditing/dispatch_interceptor_test.rb +1 -1
- data/test/auditing/unit_listener_test.rb +3 -3
- data/test/command/async_command_bus_test.rb +49 -0
- data/test/command/duplication_test.rb +2 -2
- data/test/command/gateway/interval_retry_scheduler_test.rb +42 -0
- data/test/command/gateway/retrying_callback_test.rb +57 -0
- data/test/command/gateway_test.rb +41 -7
- data/test/command/interceptor_chain_test.rb +1 -1
- data/test/command/message_test.rb +17 -0
- data/test/command/serialization_test.rb +2 -2
- data/test/command/simple_command_bus_test.rb +7 -7
- data/test/command/validation_test.rb +3 -3
- data/test/command/wiring_test.rb +3 -3
- data/test/common/concurrency/identifier_lock_test.rb +2 -13
- data/test/common/concurrency/public_lock_test.rb +6 -6
- data/test/{duplication_test.rb → common/duplication_test.rb} +3 -3
- data/test/configuration/component/command_bus/async_command_bus_test.rb +36 -0
- data/test/configuration/component/command_bus/simple_command_bus_test.rb +57 -0
- data/test/configuration/component/event_bus/simple_event_bus_test.rb +58 -0
- data/test/configuration/component/serialization/converter_factory_test.rb +48 -0
- data/test/configuration/component/serialization/serializer_test.rb +78 -0
- data/test/configuration/component/uow/unit_factory_test.rb +46 -0
- data/test/configuration/container_builder_test.rb +47 -0
- data/test/configuration/container_test.rb +88 -0
- data/test/configuration/definition_builder_test.rb +126 -0
- data/test/configuration/definition_test.rb +41 -0
- data/test/configuration/dependent_test.rb +30 -0
- data/test/configuration/ext_test.rb +19 -0
- data/test/configuration/fixtures/dependent.rb +10 -0
- data/test/domain/aggregate_root_test.rb +5 -5
- data/test/domain/message_test.rb +15 -3
- data/test/domain/stream_test.rb +2 -2
- data/test/event_bus/publisher_test.rb +29 -0
- data/test/event_bus/wiring_test.rb +1 -1
- data/test/event_sourcing/aggregate_factory_test.rb +12 -6
- data/test/event_sourcing/aggregate_root_test.rb +4 -4
- data/test/event_sourcing/entity_test.rb +10 -9
- data/test/event_sourcing/repository_test.rb +6 -6
- data/test/event_sourcing/storage_listener_test.rb +8 -4
- data/test/event_store/in_memory_test.rb +3 -3
- data/test/process_manager/container_resource_injector_test.rb +19 -0
- data/test/process_manager/correlation_set_test.rb +2 -2
- data/test/process_manager/correlation_test.rb +2 -2
- data/test/process_manager/in_memory_test.rb +3 -3
- data/test/process_manager/process_factory_test.rb +2 -2
- data/test/process_manager/process_test.rb +3 -3
- data/test/process_manager/simple_process_manager_test.rb +5 -5
- data/test/process_manager/wiring/process_manager_test.rb +4 -4
- data/test/process_manager/wiring/process_test.rb +2 -2
- data/test/repository/locking_test.rb +4 -4
- data/test/repository/optimistic_test.rb +2 -2
- data/test/repository/pessimistic_test.rb +1 -1
- data/test/repository/simple_repository_test.rb +79 -0
- data/test/support/countdown_latch.rb +18 -0
- data/test/test_helper.rb +6 -3
- data/test/upcasting/data_test.rb +31 -0
- metadata +84 -25
- data/lib/synapse/event_bus/event_listener_proxy.rb +0 -12
- data/lib/synapse/partitioning/memory_queue_reader.rb +0 -31
- data/lib/synapse/partitioning/memory_queue_writer.rb +0 -19
- data/lib/synapse/partitioning/message_receipt.rb +0 -25
- data/lib/synapse/partitioning/packing/json_packer.rb +0 -93
- data/lib/synapse/partitioning/packing/json_unpacker.rb +0 -83
- data/lib/synapse/partitioning/packing.rb +0 -27
- data/lib/synapse/partitioning/queue_reader.rb +0 -32
- data/lib/synapse/partitioning/queue_writer.rb +0 -17
- data/lib/synapse/partitioning.rb +0 -18
- data/test/partitioning/memory_test.rb +0 -34
- data/test/partitioning/packing/json_test.rb +0 -62
@@ -1,31 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Queue reader that dequeues messages from an in-memory Ruby queue
|
4
|
-
class MemoryQueueReader < QueueReader
|
5
|
-
# @param [Queue] queue
|
6
|
-
# @param [String] name Name of the queue being read from
|
7
|
-
# @return [undefined]
|
8
|
-
def initialize(queue, name)
|
9
|
-
@queue = queue
|
10
|
-
@name = name
|
11
|
-
end
|
12
|
-
|
13
|
-
# @yield [MessageReceipt] Receipt of the message taken off the queue
|
14
|
-
# @return [undefined]
|
15
|
-
def subscribe(&handler)
|
16
|
-
loop do
|
17
|
-
packed = @queue.pop
|
18
|
-
|
19
|
-
receipt = MessageReceipt.new 0, packed, @name
|
20
|
-
handler.call receipt
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# @param [MessageReceipt] receipt
|
25
|
-
# @return [undefined]
|
26
|
-
def nack_message(receipt)
|
27
|
-
@queue.push receipt.packed
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Queue writer that pushes message into an in-memory Ruby queue
|
4
|
-
class MemoryQueueWriter < QueueWriter
|
5
|
-
# @param [Queue] queue
|
6
|
-
# @return [undefined]
|
7
|
-
def initialize(queue)
|
8
|
-
@queue = queue
|
9
|
-
end
|
10
|
-
|
11
|
-
# @param [Object] packed
|
12
|
-
# @param [Message] unpacked
|
13
|
-
# @return [undefined]
|
14
|
-
def put_message(packed, unpacked)
|
15
|
-
@queue.push packed
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Receipt used to track messages taken off of a queue
|
4
|
-
class MessageReceipt
|
5
|
-
# @return [Object] The transport mechanism's record of the message
|
6
|
-
attr_reader :tag
|
7
|
-
|
8
|
-
# @return [Object] The packed message from the transport
|
9
|
-
attr_reader :packed
|
10
|
-
|
11
|
-
# @return [String] The name of the queue the message was read from
|
12
|
-
attr_reader :queue_name
|
13
|
-
|
14
|
-
# @param [Object] tag
|
15
|
-
# @param [Object] packed
|
16
|
-
# @param [String] queue_name
|
17
|
-
# @return [undefined]
|
18
|
-
def initialize(tag, packed, queue_name)
|
19
|
-
@tag = tag
|
20
|
-
@packed = packed
|
21
|
-
@queue_name = queue_name
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Implementation of a message packer that serializes the metadata and payload of any
|
4
|
-
# message and then serializes the entire message so it can go onto the wire.
|
5
|
-
class JsonMessagePacker < MessagePacker
|
6
|
-
# @param [Serializer] serializer
|
7
|
-
# @return [undefined]
|
8
|
-
def initialize(serializer)
|
9
|
-
@serializer = serializer
|
10
|
-
|
11
|
-
@serialization_target = String
|
12
|
-
# Ideally, we want to serialize the metadata and payload to hashes so that we don't
|
13
|
-
# duplicate serialization while serializing the message as a whole to a string
|
14
|
-
if serializer.can_serialize_to? Hash
|
15
|
-
@serialization_target = Hash
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# @param [Message] unpacked
|
20
|
-
# @return [String]
|
21
|
-
def pack_message(unpacked)
|
22
|
-
message_type = type_for unpacked
|
23
|
-
|
24
|
-
metadata = @serializer.serialize unpacked.metadata, @serialization_target
|
25
|
-
payload = @serializer.serialize unpacked.payload, @serialization_target
|
26
|
-
|
27
|
-
packed = {
|
28
|
-
message_type: message_type,
|
29
|
-
id: unpacked.id,
|
30
|
-
metadata: metadata.content,
|
31
|
-
payload: payload.content,
|
32
|
-
payload_type: payload.type.name,
|
33
|
-
payload_revision: payload.type.revision
|
34
|
-
}
|
35
|
-
|
36
|
-
if [:event, :domain_event].include? message_type
|
37
|
-
pack_event unpacked, packed
|
38
|
-
end
|
39
|
-
|
40
|
-
if :domain_event == message_type
|
41
|
-
pack_domain_event unpacked, packed
|
42
|
-
end
|
43
|
-
|
44
|
-
JSON.dump packed
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# Packs additional attributes specific to event messages
|
50
|
-
#
|
51
|
-
# @param [EventMessage] unpacked
|
52
|
-
# @param [Hash] packed
|
53
|
-
# @return [undefined]
|
54
|
-
def pack_event(unpacked, packed)
|
55
|
-
additional = {
|
56
|
-
timestamp: unpacked.timestamp.to_i
|
57
|
-
}
|
58
|
-
packed.merge! additional
|
59
|
-
end
|
60
|
-
|
61
|
-
# Packs additional attributes specific to domain event messages
|
62
|
-
#
|
63
|
-
# @param [DomainEventMessage] unpacked
|
64
|
-
# @param [Hash] packed
|
65
|
-
# @return [undefined]
|
66
|
-
def pack_domain_event(unpacked, packed)
|
67
|
-
additional = {
|
68
|
-
aggregate_id: unpacked.aggregate_id.to_s,
|
69
|
-
sequence_number: unpacked.sequence_number
|
70
|
-
}
|
71
|
-
packed.merge! additional
|
72
|
-
end
|
73
|
-
|
74
|
-
# Returns the packed type for the given message
|
75
|
-
#
|
76
|
-
# @raise [ArgumentError] If the given message isn't supported by this packer
|
77
|
-
# @param [Message] unpacked
|
78
|
-
# @return [Symbol]
|
79
|
-
def type_for(unpacked)
|
80
|
-
case unpacked
|
81
|
-
when Command::CommandMessage
|
82
|
-
:command
|
83
|
-
when Domain::DomainEventMessage
|
84
|
-
:domain_event
|
85
|
-
when Domain::EventMessage
|
86
|
-
:event
|
87
|
-
else
|
88
|
-
raise ArgumentError, 'Unknown message type'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end # JsonMessagePacker
|
92
|
-
end # Partitioning
|
93
|
-
end # Synapse
|
@@ -1,83 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Implementation of a message unpacker that unpacks messages that come off the wire in the
|
4
|
-
# format described by JsonMessagePacker
|
5
|
-
class JsonMessageUnpacker < MessageUnpacker
|
6
|
-
# @param [Serializer] serializer
|
7
|
-
# @return [undefined]
|
8
|
-
def initialize(serializer)
|
9
|
-
@serializer = serializer
|
10
|
-
end
|
11
|
-
|
12
|
-
# @param [String] packed
|
13
|
-
# @return [Message]
|
14
|
-
def unpack_message(message)
|
15
|
-
packed = JSON.load message
|
16
|
-
packed.symbolize_keys!
|
17
|
-
|
18
|
-
message_type = packed.fetch(:message_type).to_sym
|
19
|
-
builder = builder_for(message_type).new
|
20
|
-
|
21
|
-
builder.id = packed.fetch :id
|
22
|
-
builder.metadata = deserialize_metadata packed
|
23
|
-
builder.payload = deserialize_payload packed
|
24
|
-
|
25
|
-
if [:event, :domain_event].include? message_type
|
26
|
-
timestamp = packed.fetch :timestamp
|
27
|
-
builder.timestamp = Time.at timestamp
|
28
|
-
end
|
29
|
-
|
30
|
-
if :domain_event == message_type
|
31
|
-
builder.aggregate_id = packed.fetch :aggregate_id
|
32
|
-
builder.sequence_number = packed.fetch :sequence_number
|
33
|
-
end
|
34
|
-
|
35
|
-
builder.build
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# Deserializes the metadata of the given packed message
|
41
|
-
#
|
42
|
-
# @param [Hash] packed
|
43
|
-
# @return [Hash]
|
44
|
-
def deserialize_metadata(packed)
|
45
|
-
content = packed.fetch :metadata
|
46
|
-
@serializer.deserialize Serialization::SerializedMetadata.new content, content.class
|
47
|
-
end
|
48
|
-
|
49
|
-
# Deserializes the payload of the given packed message
|
50
|
-
#
|
51
|
-
# @param [Hash] packed
|
52
|
-
# @return [Object]
|
53
|
-
def deserialize_payload(packed)
|
54
|
-
content = packed.fetch :payload
|
55
|
-
name = packed.fetch :payload_type
|
56
|
-
revision = packed.fetch :payload_revision
|
57
|
-
|
58
|
-
serialized_type = Serialization::SerializedType.new name, revision
|
59
|
-
serialized_object = Serialization::SerializedObject.new content, content.class, serialized_type
|
60
|
-
|
61
|
-
@serializer.deserialize serialized_object
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns the builder type for the given message type
|
65
|
-
#
|
66
|
-
# @raise [ArgumentError] If message type isn't supported by this unpacker
|
67
|
-
# @param [Symbol] type
|
68
|
-
# @return [Class]
|
69
|
-
def builder_for(type)
|
70
|
-
case type
|
71
|
-
when :command
|
72
|
-
Command::CommandMessage.builder
|
73
|
-
when :domain_event
|
74
|
-
Domain::DomainEventMessage.builder
|
75
|
-
when :event
|
76
|
-
Domain::EventMessage.builder
|
77
|
-
else
|
78
|
-
raise ArgumentError, 'Unknown message type'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end # JsonMessageUnpacker
|
82
|
-
end # Partitioning
|
83
|
-
end # Synapse
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Represents a mechanism for packing a message into a string so that it can be either stored
|
4
|
-
# in a file or passed over a transport mechanism to be unpacked at the receiver
|
5
|
-
#
|
6
|
-
# This implementation simply returns the message as-is
|
7
|
-
class MessagePacker
|
8
|
-
# @param [Message] unpacked
|
9
|
-
# @return [String]
|
10
|
-
def pack_message(unpacked)
|
11
|
-
unpacked
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Represents a mechanism for unpacking a message that has been packed for storage in a file
|
16
|
-
# or transport from a producer
|
17
|
-
#
|
18
|
-
# This implementation simply returns the message as-is
|
19
|
-
class MessageUnpacker
|
20
|
-
# @param [String] packed
|
21
|
-
# @return [Message]
|
22
|
-
def unpack_message(packed)
|
23
|
-
packed
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Represents a mechanism for taking messages off a queue and handling the acknowledgement
|
4
|
-
# or rejection of each message
|
5
|
-
#
|
6
|
-
# @abstract
|
7
|
-
class QueueReader
|
8
|
-
# Subscribes the given handler to the queue
|
9
|
-
#
|
10
|
-
# Depending on the implementation, this method may or may not return immediately. It should
|
11
|
-
# be assumed that the method will block until a message is received and then will go back
|
12
|
-
# to blocking after the given callback is invoked.
|
13
|
-
#
|
14
|
-
# @abstract
|
15
|
-
# @yield [MessageReceipt] Receipt of the message taken off the queue
|
16
|
-
# @return [undefined]
|
17
|
-
def subscribe(&handler); end
|
18
|
-
|
19
|
-
# Acknowledges the message, removing it from the original queue
|
20
|
-
#
|
21
|
-
# @param [MessageReceipt] receipt
|
22
|
-
# @return [undefined]
|
23
|
-
def ack_message(receipt); end
|
24
|
-
|
25
|
-
# Attempts to notify the original queue that the message was not processed
|
26
|
-
#
|
27
|
-
# @param [MessageReceipt] receipt
|
28
|
-
# @return [undefined]
|
29
|
-
def nack_message(receipt); end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
# Represents a mechanism for writing packed messages to a queue
|
4
|
-
# @abstract
|
5
|
-
class QueueWriter
|
6
|
-
# Enqueues the given message
|
7
|
-
#
|
8
|
-
# Depending on the implementation, this method may or may not block until the message has
|
9
|
-
# been enqueued.
|
10
|
-
#
|
11
|
-
# @param [Object] packed
|
12
|
-
# @param [Message] unpacked
|
13
|
-
# @return [undefined]
|
14
|
-
def put_message(packed, unpacked); end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/synapse/partitioning.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Synapse
|
2
|
-
module Partitioning
|
3
|
-
extend ActiveSupport::Autoload
|
4
|
-
|
5
|
-
# Optional queues
|
6
|
-
autoload :MemoryQueueReader
|
7
|
-
autoload :MemoryQueueWriter
|
8
|
-
|
9
|
-
# Optional message packing
|
10
|
-
autoload :JsonMessagePacker, 'synapse/partitioning/packing/json_packer'
|
11
|
-
autoload :JsonMessageUnpacker, 'synapse/partitioning/packing/json_unpacker'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'synapse/partitioning/message_receipt'
|
16
|
-
require 'synapse/partitioning/packing'
|
17
|
-
require 'synapse/partitioning/queue_reader'
|
18
|
-
require 'synapse/partitioning/queue_writer'
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Synapse
|
4
|
-
module Partitioning
|
5
|
-
|
6
|
-
class MemoryQueueTest < Test::Unit::TestCase
|
7
|
-
def test_queuing
|
8
|
-
message = MessageBuilder.build
|
9
|
-
|
10
|
-
queue = Queue.new
|
11
|
-
|
12
|
-
reader = MemoryQueueReader.new queue, :test
|
13
|
-
writer = MemoryQueueWriter.new queue
|
14
|
-
|
15
|
-
count = 0
|
16
|
-
|
17
|
-
Thread.new do
|
18
|
-
reader.subscribe do |receipt|
|
19
|
-
assert_equal message, receipt.packed
|
20
|
-
assert_equal :test, receipt.queue_name
|
21
|
-
|
22
|
-
count = count.next
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
writer.put_message message, message
|
27
|
-
writer.put_message message, message
|
28
|
-
|
29
|
-
wait_until { count == 2 }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Synapse
|
4
|
-
module Partitioning
|
5
|
-
|
6
|
-
class JsonPackingTest < Test::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
@converter_factory = Serialization::ConverterFactory.new
|
9
|
-
@serializer = Serialization::MarshalSerializer.new @converter_factory
|
10
|
-
@packer = JsonMessagePacker.new @serializer
|
11
|
-
@unpacker = JsonMessageUnpacker.new @serializer
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_packing
|
15
|
-
message = Domain::DomainEventMessage.build do |builder|
|
16
|
-
builder.metadata = { foo: 0 }
|
17
|
-
builder.payload = { bar: 1 }
|
18
|
-
builder.aggregate_id = '123'
|
19
|
-
builder.sequence_number = 1
|
20
|
-
end
|
21
|
-
|
22
|
-
packed = @packer.pack_message message
|
23
|
-
unpacked = @unpacker.unpack_message packed
|
24
|
-
|
25
|
-
assert_equal message.id, unpacked.id
|
26
|
-
assert_equal message.metadata, unpacked.metadata
|
27
|
-
assert_equal message.payload, unpacked.payload
|
28
|
-
assert_equal message.timestamp.to_i, unpacked.timestamp.to_i
|
29
|
-
assert_equal message.aggregate_id, unpacked.aggregate_id
|
30
|
-
assert_equal message.sequence_number, unpacked.sequence_number
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_type_packing
|
34
|
-
[Command::CommandMessage, Domain::EventMessage, Domain::DomainEventMessage].each do |type|
|
35
|
-
message = type.build
|
36
|
-
packed = @packer.pack_message message
|
37
|
-
unpacked = @unpacker.unpack_message packed
|
38
|
-
|
39
|
-
assert type === unpacked
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_unknown_type
|
44
|
-
message = Message.build
|
45
|
-
|
46
|
-
assert_raise ArgumentError do
|
47
|
-
@packer.pack_message message
|
48
|
-
end
|
49
|
-
|
50
|
-
packed = {
|
51
|
-
message_type: :message
|
52
|
-
}
|
53
|
-
packed = JSON.dump packed
|
54
|
-
|
55
|
-
assert_raise ArgumentError do
|
56
|
-
@unpacker.unpack_message packed
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|