Пример #1
0
    def test_io_component_with_invalid_streams(self):
        # no streams
        with pytest.raises(ComponentBuildError):
            component = ComponentBuilder.build(SubIOComponent, self.config)

        # no output stream
        with pytest.raises(ComponentBuildError):
            component = ComponentBuilder.build(SubIOComponent, self.config,
                                               self.input_stream)

        # no input stream
        with pytest.raises(ComponentBuildError):
            component = ComponentBuilder.build(
                SubIOComponent, self.config, output_stream=self.output_stream)
Пример #2
0
def serve_component(component_class: type,
                    serving_config: ComponentServerConfig,
                    middleware: List[Callable] = None):
    # connect to system manager
    system_client = get_system_client(serving_config.system_config)
    # check dependencies for streams
    system_client.wait_for_dependencies(
        serving_config.stream_config.dependencies)
    # create streams
    input_stream, output_stream = stream_factory(serving_config.stream_config)
    # check dependencies for component
    system_client.wait_for_dependencies(
        serving_config.component_config.dependencies)
    # create component
    component = ComponentBuilder.build(component_class,
                                       serving_config.component_config,
                                       input_stream, output_stream)
    # create component manager
    component_manager = ComponentManager(component)
    # setup server
    if not middleware:
        middleware = get_default_middleware()
    server_manager = ServerManager(middleware)
    # register component endpoints with server
    component_manager.register_endpoints(server_manager)
    # register component with system
    client_config = get_component_client_config(
        serving_config.component_config, serving_config.network_config)
    system_client.register_component(client_config)

    return server_manager.get_server()
Пример #3
0
    def test_build_input_component(self):
        component = ComponentBuilder.build(SubInputComponent,
                                           self.config,
                                           input_stream=self.input_stream)
        assert isinstance(component, SubInputComponent)

        assert self.config == component.config
        assert self.input_stream == component.input_stream
Пример #4
0
    def test_build_io_component(self):
        component = ComponentBuilder.build(SubIOComponent, self.config,
                                           self.input_stream,
                                           self.output_stream)
        assert isinstance(component, SubIOComponent)

        assert self.config == component.config
        assert self.input_stream == component.input_stream
        assert self.output_stream == component.output_stream
Пример #5
0
 def test_build_invalid_component(self):
     with pytest.raises(ComponentBuildError):
         component = ComponentBuilder.build(TestComponent, self.config,
                                            self.input_stream,
                                            self.output_stream)
Пример #6
0
 def test_input_component_with_invalid_streams(self):
     # no output stream
     with pytest.raises(ComponentBuildError):
         component = ComponentBuilder.build(SubInputComponent, self.config)