def test_filter_policy_by_concept(): class CommandMatch(ApplicationCommand): __concept__: str = 'ConceptMatch' __version__: int = 1 class CommandNotMatch(ApplicationCommand): __concept__: str = 'ConceptNotMatch' __version__: int = 1 command_match = CommandMatch.stamp()() command_not_match = CommandNotMatch.stamp()() subscriber = BasicSubscriber() bus = Bus() bus.attach( FilterPolicy( concepts=[CommandMatch.__concept__], targets=[subscriber] ) ) bus.publish(command_match) bus.publish(command_not_match) assert len(subscriber) == 1 assert subscriber[0] == command_match
def test_filter_policy_by_context(): context = "ctx" command_match = ApplicationCommand.stamp()( __context__ = context, __version__ = 1 ) command_not_match = ApplicationCommand.stamp()( __context__ = None, __version__ = 1 ) subscriber = BasicSubscriber() bus = Bus() bus.attach( FilterPolicy( contexts=[context], targets=[subscriber] ) ) bus.publish(command_match) bus.publish(command_not_match) assert len(subscriber) == 1 assert subscriber[0] == command_match
def __init__( self, environment: ContextEnvironment, event_processor: EventProcessor, publisher_bus: Bus[InfrastructureMessage], ) -> None: self.environment = environment self.event_processor = event_processor self.domain_events = BasicSubscriber() publisher_bus.attach( FilterPolicy(types=[DomainEvent], targets=[self.domain_events]) ) self.integration_events = BasicSubscriber() publisher_bus.attach( FilterPolicy( types=[IntegrationEvent], targets=[self.integration_events] ) )
def __init__( self, environment: ContextMapEnvironment, integration_event_publisher_bus: Bus[IntegrationEvent], ): self.environment = environment self.integration_events = BasicSubscriber() integration_event_publisher_bus.attach(self.integration_events) self.sequences: typing.Dict[str, typing.Iterator] = {}
def test_watch_resolution_bus(mapper, trace_id, command, integration_success): integration_subscriber = BasicSubscriber() integration_bus = Bus() integration_bus.attach(integration_subscriber) store = MemoryTraceStore(mapper) store.start_trace(command) store.resolve_context(integration_success) store.watch_trace_resolution(trace_id, integration_bus=integration_bus) assert len(integration_subscriber) == 1
def test_watch_resolution_bus(dynamodb, mapper, trace_table_name, region_name, trace_id, command, integration_success): integration_subscriber = BasicSubscriber() integration_bus = Bus() integration_bus.attach(integration_subscriber) store = DynamoDBTraceStore(trace_table_name, mapper, region_name=region_name) store.start_trace(command) store.resolve_context(integration_success) store.watch_trace_resolution(trace_id, integration_bus=integration_bus) assert len(integration_subscriber) == 1
def test_filter_policy_by_type(): message_match = ApplicationCommand.stamp()(__version__=1) message_not_match = ApplicationQuery.stamp()(__version__=1) subscriber = BasicSubscriber() bus = Bus() bus.attach( FilterPolicy( types=[ApplicationCommand], targets=[subscriber] ) ) bus.publish(message_match) bus.publish(message_not_match) assert len(subscriber) == 1 assert subscriber[0] == message_match
def bus_subscriber(): return BasicSubscriber()