def test_create_update_handler_throws_if_protocol_not_specified():
    producer = FakeProducer()
    channel_with_no_protocol = Channel(
        "name", EpicsProtocol.NONE, "output_topic", "f142"
    )
    with pytest.raises(RuntimeError):
        create_update_handler(producer, None, None, channel_with_no_protocol, 20000)  # type: ignore
def test_create_update_handler_throws_if_channel_has_no_schema():
    producer = FakeProducer()
    channel_with_no_topic = Channel("name", EpicsProtocol.PVA, "output_topic", None)
    with pytest.raises(RuntimeError):
        create_update_handler(producer, None, None, channel_with_no_topic, 20000)  # type: ignore

    channel_with_empty_topic = Channel("name", EpicsProtocol.PVA, "output_topic", "")
    with pytest.raises(RuntimeError):
        create_update_handler(producer, None, None, channel_with_empty_topic, 20000)  # type: ignore
예제 #3
0
def _subscribe_to_pv(
    new_channel: Channel,
    update_handlers: Dict[Channel, UpdateHandler],
    producer: KafkaProducer,
    ca_ctx: CaContext,
    pva_ctx: PvaContext,
    logger: Logger,
    fake_pv_period: int,
    pv_update_period: Optional[int],
):
    if new_channel in update_handlers.keys():
        logger.warning(
            "Forwarder asked to subscribe to PV it is already has an identical configuration for"
        )
        return

    try:
        update_handlers[new_channel] = create_update_handler(
            producer,
            ca_ctx,
            pva_ctx,
            new_channel,
            fake_pv_period,
            periodic_update_ms=pv_update_period,
        )
    except RuntimeError as error:
        logger.error(str(error))
    logger.info(
        f"Subscribed to PV name='{new_channel.name}', schema='{new_channel.schema}', topic='{new_channel.output_topic}'"
    )
def test_pva_handler_created_when_pva_protocol_specified():
    producer = FakeProducer()
    context = FakePVAContext()
    channel_with_pva_protocol = Channel(
        "name", EpicsProtocol.PVA, "output_topic", "f142"
    )
    handler = create_update_handler(producer, None, context, channel_with_pva_protocol, 20000)  # type: ignore
    assert isinstance(handler, PVAUpdateHandler)