def test_get_payload_stream_not_exists_ok(self): manager = StreamManager(None) identifier: UUID = uuid4() stream = manager.get_payload_stream(Header(id=identifier)) self.assertIsNotNone(stream)
def test_get_payload_assembler_exists_ok(self): manager = StreamManager(None) identifier: UUID = uuid4() assembler1 = manager.get_payload_assembler(identifier) assembler2 = manager.get_payload_assembler(identifier) self.assertEqual(assembler1, assembler2)
def test_get_payload_stream_streams_match(self): manager = StreamManager(None) identifier: UUID = uuid4() assembler = manager.get_payload_assembler(identifier) stream = manager.get_payload_stream(Header(id=identifier)) self.assertEqual(assembler.get_payload_as_stream(), stream)
def test_get_payload_stream_exists_ok(self): manager = StreamManager(None) identifier: UUID = uuid4() stream1 = manager.get_payload_stream(Header(id=identifier)) stream2 = manager.get_payload_stream(Header(id=identifier)) self.assertEqual(stream1, stream2)
def test_get_payload_assembler_not_exists_ok(self): manager = StreamManager(None) identifier: UUID = uuid4() assembler = manager.get_payload_assembler(identifier) self.assertIsNotNone(assembler) self.assertEqual(identifier, assembler.identifier)
def test_on_receive_exists(self): manager = StreamManager(None) identifier: UUID = uuid4() assembler = manager.get_payload_assembler(identifier) assembler.get_payload_as_stream() manager.on_receive(Header(id=identifier, end=True), [], 100) self.assertTrue(assembler.end)
def test_close_stream_not_end_closed(self): closed = False def mock_cancel_stream(_: PayloadStreamAssembler): nonlocal closed closed = True manager = StreamManager(on_cancel_stream=mock_cancel_stream) identifier: UUID = uuid4() assembler = manager.get_payload_assembler(identifier) assembler.get_payload_as_stream() manager.close_stream(identifier) self.assertTrue(closed)
def __init__( self, request_handler: RequestHandler, request_manager: RequestManager, payload_sender: PayloadSender, payload_receiver: PayloadReceiver, handler_context: object = None, ): self._request_handler = request_handler self._request_manager = request_manager self._payload_sender = payload_sender self._payload_receiver = payload_receiver self._handler_context = handler_context self._send_operations = SendOperations(self._payload_sender) # TODO: might be able to remove self._stream_manager = StreamManager(self._on_cancel_stream) self._assembler_manager = PayloadAssemblerManager( self._stream_manager, self._on_receive_request, self._on_receive_response ) self._payload_receiver.subscribe( self._assembler_manager.get_payload_stream, self._assembler_manager.on_receive, )
def test_get_stream_does_not_make_new_each_time(self): identifier: UUID = uuid4() stream_manager = StreamManager() assembler = PayloadStreamAssembler(stream_manager, identifier) stream1 = assembler.get_payload_as_stream() stream2 = assembler.get_payload_as_stream() self.assertEqual(stream1, stream2)
def test_close_stream_end_no_op(self): closed = False def mock_cancel_stream(_: PayloadStreamAssembler): nonlocal closed closed = True manager = StreamManager(on_cancel_stream=mock_cancel_stream) identifier: UUID = uuid4() assembler = manager.get_payload_assembler(identifier) assembler.get_payload_as_stream() assembler.on_receive(Header(end=True), [], 1) # Set it as ended manager.close_stream(identifier) self.assertFalse(closed)
def test_close_does_not_set_end(self): identifier: UUID = uuid4() stream_manager = StreamManager() assembler = PayloadStreamAssembler(stream_manager, identifier) assembler.close() self.assertFalse(assembler.end)
def test_on_receive_sets_end(self): identifier: UUID = uuid4() stream_manager = StreamManager() assembler = PayloadStreamAssembler(stream_manager, identifier) header = Header() header.end = True assembler.get_payload_as_stream() assembler.on_receive(header, [], 100) self.assertTrue(assembler.end)
def test_ctor_null_cancel_ok(self): manager = StreamManager(None) self.assertIsNotNone(manager)
def test_ctor_id(self): identifier: UUID = uuid4() stream_manager = StreamManager() assembler = PayloadStreamAssembler(stream_manager, identifier) self.assertEqual(identifier, assembler.identifier)
def test_get_stream(self): identifier: UUID = uuid4() stream_manager = StreamManager() assembler = PayloadStreamAssembler(stream_manager, identifier) stream = assembler.get_payload_as_stream() self.assertIsNotNone(stream)
def test_ctor_end_false(self): identifier: UUID = uuid4() stream_manager = StreamManager() assembler = PayloadStreamAssembler(stream_manager, identifier) self.assertFalse(assembler.end)
def test_on_receive_not_exists_no_op(self): manager = StreamManager(None) identifier: UUID = uuid4() manager.on_receive(Header(id=identifier), [], 100)
def test_close_stream_not_exists_no_op(self): manager = StreamManager(None) identifier: UUID = uuid4() manager.close_stream(identifier)