def test_when_error_in_output_then_pipeline_fails(): """ This function tests the integration of input and output. It assumes connectivity to streaming client is correct, therefore the steaming client is mocked. We look to find that once a message is received, it is send out by the output writer. This is the maximal integration test we can have in an isolated environment. :return: """ # setup input input_client_mock = StreamingClientMock() ir_config = { 'APP_PORT': os.getenv("APP_PORT"), 'APP_HOST': os.getenv("APP_HOST"), } print('Creating reader') ir = InputReaderFactory.create(ir_config, input_client_mock) print('start_receiving_messages') ir.start_receiving_messages() # setup app app = TestApp(os.getenv("APP_PORT"), os.getenv("APP_HOST"), os.getenv("OUTPUT_WRITER_PORT"), os.getenv("OUTPUT_WRITER_HOST")) app.start() # setup output ow_config = { 'OUTPUT_WRITER_PORT': os.getenv("OUTPUT_WRITER_PORT"), 'OUTPUT_WRITER_HOST': os.getenv("OUTPUT_WRITER_HOST"), } print('Creating writer') output_client_mock = StreamingClientMock() ow = OutputWriterFactory.create(ow_config, output_client_mock, None) print('start_incoming_messages') # Set to fail on Output Send: output_client_mock.set_fail_send(True) print('sending test message to reader') test_msg = str(time.clock()) # send a message from INPUT reader, and expect it to flow in the pipeline, # and eventually be picked up by the output writer result = input_client_mock.fake_incoming_message_from_streaming(test_msg) last_msg = output_client_mock.get_last_msg() assert last_msg is None assert result is False ir.stop_incoming_messages() ow.stop_incoming_messages()
def test_broadcast_success(*fixtures): mock1 = StreamingClientMock() mock2 = StreamingClientMock() broadcast = BroadcastStreamingClient({'BROADCAST_CLIENTS': [mock1, mock2]}) success = broadcast.send({'test': 'message'}) assert success assert mock1.get_sent() and mock2.get_sent()
def test_broadcast_failure(*fixtures): mock1 = StreamingClientMock() mock2 = StreamingClientMock() mock3 = StreamingClientMock() broadcast = BroadcastStreamingClient( {'BROADCAST_CLIENTS': [mock1, mock2, mock3]}) mock2.set_fail_send(True) success = broadcast.send({'test': 'message'}) assert not success assert mock1.get_sent() and not mock2.get_sent() and mock3.get_sent()
def mock_streaming_client(): return StreamingClientMock()