예제 #1
0
def test_datahub_kafka_hook(mock_emitter):
    with patch_airflow_connection(datahub_kafka_connection_config) as config:
        hook = DatahubKafkaHook(config.conn_id)
        hook.emit_mces([lineage_mce])

        mock_emitter.assert_called_once()
        instance = mock_emitter.return_value
        instance.emit_mce_async.assert_called()
        instance.flush.assert_called_once()
예제 #2
0
    def __init__(
        self,
        *,
        datahub_rest_conn_id: Optional[str] = None,
        datahub_kafka_conn_id: Optional[str] = None,
        **kwargs,
    ):
        super().__init__(**kwargs)

        if datahub_rest_conn_id and datahub_kafka_conn_id:
            raise AirflowException(
                "two hook conn id given when only exactly one required")
        elif datahub_rest_conn_id:
            self.hook = DatahubRestHook(datahub_rest_conn_id)
        elif datahub_kafka_conn_id:
            self.hook = DatahubKafkaHook(datahub_kafka_conn_id)
        else:
            raise AirflowException("no hook conn id provided")