Build 060.21: integrate acquisition runtime protocols

This commit is contained in:
2026-07-26 09:20:24 +03:00
parent ad6631f773
commit 433ac5d375
4 changed files with 1914 additions and 2 deletions

View File

@@ -4,6 +4,48 @@ from __future__ import annotations
from typing import Protocol, runtime_checkable
from src.market_data.acquisition.runtime.runtime_commands import (
ConnectCommand,
DisconnectCommand,
SendBinaryCommand,
SendTextCommand,
SubscribeCommand,
UnsubscribeCommand,
)
from src.market_data.acquisition.runtime.runtime_events import (
ConnectedEvent,
ConnectFailedEvent,
DisconnectedEvent,
HeartbeatTimeoutEvent,
MessageReceivedEvent,
MessageSentEvent,
ReconnectCompletedEvent,
ReconnectFailedEvent,
ReconnectStartedEvent,
)
AcquisitionRuntimeCommand = (
ConnectCommand
| DisconnectCommand
| SubscribeCommand
| UnsubscribeCommand
| SendTextCommand
| SendBinaryCommand
)
AcquisitionRuntimeEvent = (
ConnectedEvent
| DisconnectedEvent
| ConnectFailedEvent
| MessageReceivedEvent
| MessageSentEvent
| ReconnectStartedEvent
| ReconnectCompletedEvent
| ReconnectFailedEvent
| HeartbeatTimeoutEvent
)
@runtime_checkable
class WebSocketTransportProtocol(Protocol):
@@ -76,4 +118,48 @@ class WebSocketSubscriptionManagerProtocol(Protocol):
async def clear_subscriptions(self) -> None:
"""Очистить runtime-состояние активных подписок."""
...
...
@runtime_checkable
class AcquisitionRuntimeCommandDispatcherProtocol(Protocol):
"""
Контракт передачи инфраструктурных команд в Runtime.
Dispatcher принимает только типизированные Runtime-команды
и не содержит знаний о Trade, Feed, Consistency или Recovery.
Конкретная маршрутизация и выполнение команд будут реализованы
в последующих Build.
"""
async def dispatch(
self,
command: AcquisitionRuntimeCommand,
) -> None:
"""
Передать одну инфраструктурную команду в Runtime.
"""
...
@runtime_checkable
class AcquisitionRuntimeEventPublisherProtocol(Protocol):
"""
Контракт публикации инфраструктурных событий Runtime.
Publisher передаёт уже произошедшие инфраструктурные факты
заинтересованным потребителям и не определяет их реакцию.
Конкретный механизм доставки событий будет реализован
в последующих Build.
"""
async def publish(
self,
event: AcquisitionRuntimeEvent,
) -> None:
"""
Опубликовать одно инфраструктурное событие Runtime.
"""
...

View File

@@ -3,6 +3,10 @@
from __future__ import annotations
from src.market_data.acquisition.runtime.websocket_protocol import (
AcquisitionRuntimeCommand,
AcquisitionRuntimeCommandDispatcherProtocol,
AcquisitionRuntimeEvent,
AcquisitionRuntimeEventPublisherProtocol,
WebSocketSessionProtocol,
WebSocketSubscriptionManagerProtocol,
WebSocketTransportProtocol,
@@ -43,6 +47,22 @@ class FakeWebSocketSubscriptionManager:
return None
class FakeRuntimeCommandDispatcher:
async def dispatch(
self,
command: AcquisitionRuntimeCommand,
) -> None:
return None
class FakeRuntimeEventPublisher:
async def publish(
self,
event: AcquisitionRuntimeEvent,
) -> None:
return None
def test_transport_implementation_satisfies_protocol() -> None:
assert isinstance(FakeWebSocketTransport(), WebSocketTransportProtocol)
@@ -58,9 +78,43 @@ def test_subscription_manager_implementation_satisfies_protocol() -> None:
)
def test_command_dispatcher_implementation_satisfies_protocol() -> None:
assert isinstance(
FakeRuntimeCommandDispatcher(),
AcquisitionRuntimeCommandDispatcherProtocol,
)
def test_event_publisher_implementation_satisfies_protocol() -> None:
assert isinstance(
FakeRuntimeEventPublisher(),
AcquisitionRuntimeEventPublisherProtocol,
)
def test_incomplete_transport_does_not_satisfy_protocol() -> None:
class IncompleteTransport:
async def connect(self) -> None:
return None
assert not isinstance(IncompleteTransport(), WebSocketTransportProtocol)
assert not isinstance(IncompleteTransport(), WebSocketTransportProtocol)
def test_incomplete_command_dispatcher_does_not_satisfy_protocol() -> None:
class IncompleteCommandDispatcher:
pass
assert not isinstance(
IncompleteCommandDispatcher(),
AcquisitionRuntimeCommandDispatcherProtocol,
)
def test_incomplete_event_publisher_does_not_satisfy_protocol() -> None:
class IncompleteEventPublisher:
pass
assert not isinstance(
IncompleteEventPublisher(),
AcquisitionRuntimeEventPublisherProtocol,
)